def test_filter_eio(self):
        eio_1 = EnkelvoudigInformatieObjectFactory.create()
        eio_2 = EnkelvoudigInformatieObjectFactory.create()
        eio_detail_url = f"http://example.com{reverse(eio_1)}"
        self.adapter.register_uri("GET",
                                  eio_detail_url,
                                  json=serialise_eio(eio_1, eio_detail_url))
        self.create_zaak_besluit_services()
        zaak = self.create_zaak()
        besluit = self.create_besluit()

        BesluitInformatieObjectFactory.create(informatieobject=eio_detail_url,
                                              besluit=besluit)
        ZaakInformatieObjectFactory.create(
            informatieobject=f"http://example.com{reverse(eio_2)}",
            zaak=zaak)  # may not show up

        response = self.client.get(
            self.list_url,
            {"informatieobject": eio_detail_url},
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]["informatieobject"], eio_detail_url)
    def test_read_with_objecttype_zaak(self):
        self.create_zaak_besluit_services()
        zaak = self.create_zaak()
        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))
        ZaakInformatieObjectFactory.create(zaak=zaak, informatieobject=eio_url)

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

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

        response = self.client.get(oio_url)

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

        self.assertEqual(response.status_code, status.HTTP_200_OK,
                         response.data)
        self.assertEqual(response.data, expeceted_response_data)
    def test_filter_zaak(self):
        eio_1 = EnkelvoudigInformatieObjectFactory.create()
        eio_detail_url = f"http://openzaak.nl{reverse(eio_1)}"
        self.adapter.register_uri("GET",
                                  eio_detail_url,
                                  json=serialise_eio(eio_1, eio_detail_url))

        self.create_zaak_besluit_services()
        zaak1 = self.create_zaak()
        zio = ZaakInformatieObjectFactory.create(
            informatieobject=eio_detail_url, zaak=zaak1)
        zaak2 = self.create_zaak()
        ZaakInformatieObjectFactory.create(informatieobject=eio_detail_url,
                                           zaak=zaak2)  # may not show up

        zaak_url = reverse(zio.zaak)

        response = self.client.get(
            self.list_url,
            {"object": f"http://openzaak.nl{zaak_url}"},
            HTTP_HOST="openzaak.nl",
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]["informatieobject"], eio_detail_url)
Beispiel #4
0
    def test_delete_document_fail_exising_relations_zaak(self):

        eio = EnkelvoudigInformatieObjectFactory.create()
        eio_uuid = eio.uuid
        eio_path = reverse(eio)
        eio_url = f"https://external.documenten.nl/{eio_path}"

        self.adapter.register_uri(
            "GET", eio_url, json=get_eio_response(eio_path),
        )

        ZaakInformatieObjectFactory.create(informatieobject=eio_url)

        informatieobject_delete_url = get_operation_url(
            "enkelvoudiginformatieobject_delete", uuid=eio_uuid,
        )

        response = self.client.delete(informatieobject_delete_url)

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

        error = get_validation_errors(response, "nonFieldErrors")
        self.assertEqual(error["code"], "pending-relations")
    def test_retrieve_multiple_oios(self):
        self.create_zaak_besluit_services()
        zaak = self.create_zaak()

        # This creates 2 OIOs
        eio_1 = EnkelvoudigInformatieObjectFactory.create()
        eio_1_path = reverse(eio_1)
        eio_1_url = f"http://testserver{eio_1_path}"
        # relate the two
        self.adapter.get(eio_1_url, json=serialise_eio(eio_1, eio_1_url))
        ZaakInformatieObjectFactory.create(zaak=zaak,
                                           informatieobject=eio_1_url)

        eio_2 = EnkelvoudigInformatieObjectFactory.create()
        eio_2_path = reverse(eio_2)
        eio_2_url = f"http://testserver{eio_2_path}"
        # relate the two
        self.adapter.get(eio_2_url, json=serialise_eio(eio_2, eio_2_url))
        ZaakInformatieObjectFactory.create(zaak=zaak,
                                           informatieobject=eio_2_url)

        # Retrieve oios from API
        response = self.client.get(self.list_url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.assertEqual(len(response.data), 2)
        self.assertTrue(eio_1_url == response.data[0]["informatieobject"]
                        or eio_1_url == response.data[1]["informatieobject"])
        self.assertTrue(eio_2_url == response.data[0]["informatieobject"]
                        or eio_2_url == response.data[1]["informatieobject"])
    def test_read_with_objecttype_zaak(self):
        zaak = ZaakFactory.create()
        eio = EnkelvoudigInformatieObjectFactory.create()
        eio_path = reverse(eio)
        eio_url = f"http://testserver{eio_path}"
        # relate the two
        ZaakInformatieObjectFactory.create(zaak=zaak, informatieobject=eio.canonical)

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

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

        response = self.client.get(oio_url)

        expeceted_response_data = {
            "url": f"http://testserver{oio_url}",
            "object": f"http://testserver{zaak_url}",
            "informatieobject": eio_url,
            "object_type": "zaak",
        }

        self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
        self.assertEqual(response.data, expeceted_response_data)
    def test_create_with_objecttype_zaak(self):
        zaak = ZaakFactory.create()
        eio = EnkelvoudigInformatieObjectFactory.create()
        # relate the two
        ZaakInformatieObjectFactory.create(zaak=zaak,
                                           informatieobject=eio.canonical)

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

        zaak_url = reverse(zaak)
        eio_url = reverse(eio)
        oio_url = reverse("objectinformatieobject-detail",
                          kwargs={"uuid": oio.uuid})

        response = self.client.post(
            self.list_url,
            {
                "object": f"http://testserver{zaak_url}",
                "informatieobject": f"http://testserver{eio_url}",
                "objectType": "zaak",
            },
        )

        self.assertEqual(response.status_code, status.HTTP_201_CREATED,
                         response.data)
        self.assertEqual(
            response.data,
            {
                "url": f"http://testserver{oio_url}",
                "informatieobject": f"http://testserver{eio_url}",
                "object": f"http://testserver{zaak_url}",
                "object_type": "zaak",
            },
        )
    def test_create_with_objecttype_zaak(self):
        zaak = ZaakFactory.create()
        eio = EnkelvoudigInformatieObjectFactory.create()
        eio_path = reverse(eio)
        eio_url = f"http://testserver{eio_path}"
        # relate the two
        ZaakInformatieObjectFactory.create(zaak=zaak, informatieobject=eio.canonical)

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

        zaak_url = reverse(zaak)

        response = self.client.post(
            self.list_url,
            {
                "object": f"http://testserver{zaak_url}",
                "informatieobject": eio_url,
                "objectType": "zaak",
            },
        )

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

        error = get_validation_errors(response, "nonFieldErrors")
        self.assertEqual(error["code"], "unique")
Beispiel #9
0
    def setUp(self) -> None:
        super().setUp()

        eio = EnkelvoudigInformatieObjectFactory.create()
        eio_url = f"http://openzaak.nl{reverse(eio)}"
        eio_response = serialise_eio(eio, eio_url)

        self.adapter.get(eio_url, json=eio_response)
        ZaakInformatieObjectFactory.create(informatieobject=eio_url)
        self.oio = ObjectInformatieObject.objects.get()
    def test_filter_zaak(self):
        zio = ZaakInformatieObjectFactory.create()
        ZaakInformatieObjectFactory.create()  # may not show up
        eio_detail_url = reverse(zio.informatieobject.latest_version)
        zaak_url = reverse(zio.zaak)

        response = self.client.get(self.list_url,
                                   {"object": f"http://testserver{zaak_url}"})

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]["informatieobject"],
                         f"http://testserver{eio_detail_url}")
    def test_destroy_with_relations_not_allowed(self):
        """
        Assert that destroying is not possible when there are relations.
        """
        eio = EnkelvoudigInformatieObjectFactory.create()
        ZaakInformatieObjectFactory.create(informatieobject=eio.canonical)
        url = reverse(eio)

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        error = get_validation_errors(response, "nonFieldErrors")
        self.assertEqual(error["code"], "pending-relations")
Beispiel #12
0
    def test_filter_eio(self):
        bio = BesluitInformatieObjectFactory.create()
        ZaakInformatieObjectFactory.create()  # may not show up
        eio_detail_url = reverse(bio.informatieobject.latest_version)

        response = self.client.get(
            self.list_url,
            {"informatieobject": f"http://openzaak.nl{eio_detail_url}"},
            HTTP_HOST="openzaak.nl",
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]["informatieobject"],
                         f"http://openzaak.nl{eio_detail_url}")
Beispiel #13
0
    def test_delete_document_fail_exising_relations_zaak(self):
        informatieobject = EnkelvoudigInformatieObjectCanonicalFactory.create()
        ZaakInformatieObjectFactory.create(informatieobject=informatieobject)

        informatieobject_delete_url = get_operation_url(
            "enkelvoudiginformatieobject_delete",
            uuid=informatieobject.latest_version.uuid,
        )

        response = self.client.delete(informatieobject_delete_url)

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

        error = get_validation_errors(response, "nonFieldErrors")
        self.assertEqual(error["code"], "pending-relations")
Beispiel #14
0
    def test_zio_creates_oio(self):
        zio = ZaakInformatieObjectFactory.create()

        oio = ObjectInformatieObject.objects.get()

        self.assertEqual(oio.informatieobject, zio.informatieobject)
        self.assertEqual(oio.object, zio.zaak)
Beispiel #15
0
    def test_zio_delete_oio(self):
        zio = ZaakInformatieObjectFactory.create()

        self.assertEqual(ObjectInformatieObject.objects.count(), 1)

        zio.delete()

        self.assertEqual(ObjectInformatieObject.objects.count(), 0)
Beispiel #16
0
    def test_cannot_read_without_correct_scope(self):
        eio = EnkelvoudigInformatieObjectFactory.create()
        gebruiksrechten = GebruiksrechtenFactory.create()
        ZaakInformatieObjectFactory.create()
        oio = ObjectInformatieObject.objects.get()
        urls = [
            reverse("enkelvoudiginformatieobject-list"),
            reverse("enkelvoudiginformatieobject-detail", kwargs={"uuid": eio.uuid}),
            reverse("gebruiksrechten-list"),
            reverse(gebruiksrechten),
            reverse("objectinformatieobject-list"),
            reverse(oio),
        ]

        for url in urls:
            with self.subTest(url=url):
                self.assertForbidden(url, method="get")
    def test_destroy_oio_remote_gone(self):
        zio = ZaakInformatieObjectFactory.create()
        oio = ObjectInformatieObject.objects.get()
        url = reverse(oio)
        zio.delete()

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Beispiel #18
0
    def test_zio_delete_oio(self):
        self.adapter.get(self.eio_url, json=self.eio_response)
        zio = ZaakInformatieObjectFactory.create(informatieobject=self.eio_url)

        self.assertEqual(ObjectInformatieObject.objects.count(), 1)

        zio.delete()

        self.assertEqual(ObjectInformatieObject.objects.count(), 0)
Beispiel #19
0
    def test_zio_creates_oio(self):
        self.adapter.get(self.eio_url, json=self.eio_response)
        zio = ZaakInformatieObjectFactory.create(informatieobject=self.eio_url)
        oio = ObjectInformatieObject.objects.get()

        self.assertEqual(
            oio.get_informatieobject_url(),
            zio.informatieobject._initial_data["url"],
        )
        self.assertEqual(oio.object, zio.zaak)
Beispiel #20
0
    def test_destroy_with_relations_not_allowed(self):
        """
        Assert that destroying is not possible when there are relations.
        """
        eio = EnkelvoudigInformatieObjectFactory.create()
        eio_path = reverse(eio)
        eio_url = f"https://external.documenten.nl/{eio_path}"

        self.adapter.register_uri(
            "GET", eio_url, json=get_eio_response(eio_path),
        )

        self.create_zaak_besluit_services()
        zaak = self.create_zaak()
        ZaakInformatieObjectFactory.create(informatieobject=eio_url, zaak=zaak)

        response = self.client.delete(eio_path)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        error = get_validation_errors(response, "nonFieldErrors")
        self.assertEqual(error["code"], "pending-relations")
Beispiel #21
0
    def test_cannot_read_without_correct_scope(self):
        eio = EnkelvoudigInformatieObjectFactory.create()
        eio_url = f"http://testserver{reverse(eio)}"
        gebruiksrechten = GebruiksrechtenCMISFactory.create(
            informatieobject=eio_url)

        self.adapter.get(eio_url, json=get_eio_response(reverse(eio)))
        ZaakInformatieObjectFactory.create(informatieobject=eio_url)
        oio = ObjectInformatieObject.objects.get()
        urls = [
            reverse("enkelvoudiginformatieobject-list"),
            reverse("enkelvoudiginformatieobject-detail",
                    kwargs={"uuid": eio.uuid}),
            reverse("gebruiksrechten-list"),
            reverse(gebruiksrechten),
            reverse("objectinformatieobject-list"),
            reverse(oio),
        ]

        for url in urls:
            with self.subTest(url=url):
                self.assertForbidden(url, method="get")
Beispiel #22
0
    def test_filter_eio(self):
        eio_1 = EnkelvoudigInformatieObjectFactory.create()
        eio_2 = EnkelvoudigInformatieObjectFactory.create()
        eio_detail_url = f"http://openzaak.nl{reverse(eio_1)}"
        self.adapter.register_uri("GET",
                                  eio_detail_url,
                                  json=serialise_eio(eio_1, eio_detail_url))

        BesluitInformatieObjectFactory.create(informatieobject=eio_detail_url)
        ZaakInformatieObjectFactory.create(
            informatieobject=f"http://openzaak.nl{reverse(eio_2)}"
        )  # may not show up

        response = self.client.get(
            self.list_url,
            {"informatieobject": eio_detail_url},
            HTTP_HOST="openzaak.nl",
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]["informatieobject"], eio_detail_url)
    def test_delete_document_fail_exising_relations_zaak(self):

        eio = EnkelvoudigInformatieObjectFactory.create()
        eio_uuid = eio.uuid
        eio_url = eio.get_url()

        self.create_zaak_besluit_services()
        zaak = self.create_zaak()
        ZaakInformatieObjectFactory.create(informatieobject=eio_url, zaak=zaak)

        informatieobject_delete_url = get_operation_url(
            "enkelvoudiginformatieobject_delete",
            uuid=eio_uuid,
        )

        response = self.client.delete(informatieobject_delete_url)

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

        error = get_validation_errors(response, "nonFieldErrors")
        self.assertEqual(error["code"], "pending-relations")
    def test_destroy_oio_remote_gone(self):
        eio = EnkelvoudigInformatieObjectFactory.create()

        # relate the two
        zio = ZaakInformatieObjectFactory.create(informatieobject=eio.canonical)

        oio = ObjectInformatieObject.objects.get()
        url = reverse(oio)
        zio.delete()

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Beispiel #25
0
    def test_destroy_oio_remote_gone(self):
        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))
        zio = ZaakInformatieObjectFactory.create(informatieobject=eio_url)

        oio = ObjectInformatieObject.objects.get()
        url = reverse(oio)
        zio.delete()

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
    def test_zaaktype_detail_external_io_not_available(self):
        zaak = ZaakFactory.create()
        zio = ZaakInformatieObjectFactory.create(zaak=zaak)
        zio._informatieobject = None
        zio._informatieobject_url = "http://bla.com/404"
        zio.save()

        url = reverse("admin:zaken_zaak_change", args=(zaak.pk,))

        with requests_mock.Mocker() as m:
            m.get("http://bla.com/404", status_code=404, json={})
            response = self.app.get(url)

        self.assertEqual(response.status_code, 200)

        self.assertIn("http://bla.com/404", response.text)
Beispiel #27
0
    def test_create_objectinformatieobject_audittrail(self):
        informatieobject = EnkelvoudigInformatieObjectFactory.create()
        zio = ZaakInformatieObjectFactory.create(
            informatieobject=informatieobject.canonical)

        content = {
            "informatieobject":
            reverse(
                "enkelvoudiginformatieobject-detail",
                kwargs={"uuid": informatieobject.uuid},
            ),
            "object":
            reverse(zio.zaak),
            "objectType":
            ObjectTypes.zaak,
        }

        # Send to the API
        objectinformatieobject_response = self.client.post(
            self.objectinformatieobject_list_url, content).data

        informatieobject_url = objectinformatieobject_response[
            "informatieobject"]
        audittrails = AuditTrail.objects.filter(
            hoofd_object=informatieobject_url)
        self.assertEqual(audittrails.count(), 1)

        # Verify that the audittrail for the ObjectInformatieObject creation
        # contains the correct information
        objectinformatieobject_create_audittrail = audittrails.get()
        self.assertEqual(objectinformatieobject_create_audittrail.bron, "DRC")
        self.assertEqual(objectinformatieobject_create_audittrail.actie,
                         "create")
        self.assertEqual(objectinformatieobject_create_audittrail.resultaat,
                         201)
        self.assertEqual(objectinformatieobject_create_audittrail.oud, None)
        self.assertEqual(
            objectinformatieobject_create_audittrail.nieuw,
            objectinformatieobject_response,
        )
    def test_delete_no_url_mapping(self):
        eio = EnkelvoudigInformatieObjectFactory.create()
        eio_url = eio.get_url()
        self.adapter.get(eio_url, json=serialise_eio(eio, eio_url))
        self.create_zaak_besluit_services()
        zaak = self.create_zaak()
        zio = ZaakInformatieObjectFactory.create(informatieobject=eio_url,
                                                 zaak=zaak)
        zio_url = reverse(zio)

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

        response = self.client.delete(zio_url)

        # 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 #29
0
    def setUpTestData(cls):
        super().setUpTestData()

        ZaakInformatieObjectFactory.create()
        cls.oio = ObjectInformatieObject.objects.get()