def test_zaaktype_external_iotype_internal(self):
        catalogus = f"{self.base}catalogussen/1c8e36be-338c-4c07-ac5e-1adf55bec04a"
        zaaktype = f"{self.base}zaaktypen/b71f72ef-198d-44d8-af64-ae1932df830a"
        zaak = ZaakFactory.create(zaaktype=zaaktype)
        zaak_url = f"http://openzaak.nl{reverse(zaak)}"
        informatieobjecttype = InformatieObjectTypeFactory.create()
        eio_response = get_eio_response(
            self.document,
            informatieobjecttype=f"http://openzaak.nl{reverse(informatieobjecttype)}",
        )

        with requests_mock.Mocker(real_http=True) as m:
            m.get(zaaktype, json=get_zaaktype_response(catalogus, zaaktype))
            m.get(self.document, json=eio_response)

            response = self.client.post(
                self.list_url,
                {"zaak": zaak_url, "informatieobject": self.document},
                HTTP_HOST="openzaak.nl",
            )

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

        error = get_validation_errors(response, "nonFieldErrors")
        self.assertEqual(
            error["code"], "missing-zaaktype-informatieobjecttype-relation"
        )
Example #2
0
    def test_integrity_empty(self):
        """
        Assert that integrity is optional.
        """
        informatieobjecttype = InformatieObjectTypeFactory.create(
            concept=False)
        informatieobjecttype_url = reverse(informatieobjecttype)
        content = {
            "identificatie": uuid.uuid4().hex,
            "bronorganisatie": "159351741",
            "creatiedatum": "2018-12-13",
            "titel": "Voorbeelddocument",
            "auteur": "test_auteur",
            "formaat": "text/plain",
            "taal": "eng",
            "bestandsnaam": "dummy.txt",
            "vertrouwelijkheidaanduiding": "openbaar",
            "inhoud": b64encode(b"some file content").decode("utf-8"),
            "informatieobjecttype":
            f"http://testserver{informatieobjecttype_url}",
            "integriteit": None,
        }

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

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        stored_object = EnkelvoudigInformatieObject.objects.get()
        self.assertEqual(stored_object.integriteit, {
            "algoritme": "",
            "waarde": "",
            "datum": None
        })
    def test_destroy_with_external_informatieobject_fail_send(self):
        oio = f"{self.base}objectinformatieobjecten/{uuid.uuid4()}"
        informatieobjecttype = InformatieObjectTypeFactory.create()

        with requests_mock.Mocker(real_http=True) as m:
            m.get(
                self.document,
                json=get_eio_response(
                    self.document,
                    informatieobjecttype=f"http://openzaak.nl{reverse(informatieobjecttype)}",
                ),
            )
            m.delete(oio, status_code=404, text="Not found")

            zio = ZaakInformatieObjectFactory.create(
                informatieobject=self.document, _objectinformatieobject_url=oio
            )
            zio_url = reverse(zio)

            response = self.client.delete(zio_url, HTTP_HOST="openzaak.nl")

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

        error = get_validation_errors(response, "informatieobject")
        self.assertEqual(error["code"], "pending-relations")
    def test_zaaktype_internal_iotype_internal_fail(self):
        zaak = ZaakFactory.create()
        zaak_url = f"http://openzaak.nl{reverse(zaak)}"
        informatieobjecttype = InformatieObjectTypeFactory.create()
        eio_response = get_eio_response(
            self.document,
            informatieobjecttype=
            f"http://openzaak.nl{reverse(informatieobjecttype)}",
        )

        with requests_mock.Mocker(real_http=True) as m:
            m.get(self.document, json=eio_response)
            response = self.client.post(
                self.list_url,
                {
                    "zaak": zaak_url,
                    "informatieobject": self.document
                },
                HTTP_HOST="openzaak.nl",
            )

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

        error = get_validation_errors(response, "nonFieldErrors")
        self.assertEqual(error["code"],
                         "missing-zaaktype-informatieobjecttype-relation")
    def test_create_ignores_lock(self):
        informatieobjecttype = InformatieObjectTypeFactory.create(concept=False)
        informatieobjecttype_url = reverse(informatieobjecttype)
        url = get_operation_url("enkelvoudiginformatieobject_create")
        data = {
            "identificatie": uuid.uuid4().hex,
            "bronorganisatie": "159351741",
            "creatiedatum": "2018-06-27",
            "titel": "detailed summary",
            "auteur": "test_auteur",
            "formaat": "txt",
            "taal": "eng",
            "bestandsnaam": "dummy.txt",
            "inhoud": b64encode(b"some file content").decode("utf-8"),
            "link": "http://een.link",
            "beschrijving": "test_beschrijving",
            "informatieobjecttype": f"http://testserver{informatieobjecttype_url}",
            "vertrouwelijkheidaanduiding": "openbaar",
            "lock": uuid.uuid4().hex,
        }

        response = self.client.post(url, data)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data)
        self.assertNotIn("lock", response.data)
Example #6
0
    def test_invalid_inhoud(self):
        informatieobjecttype = InformatieObjectTypeFactory.create(
            concept=False)
        informatieobjecttype_url = reverse(informatieobjecttype)
        content = {
            "identificatie": uuid.uuid4().hex,
            "bronorganisatie": "159351741",
            "creatiedatum": "2018-06-27",
            "titel": "detailed summary",
            "auteur": "test_auteur",
            "formaat": "txt",
            "taal": "eng",
            "bestandsnaam": "dummy.txt",
            "inhoud": [1, 2, 3],
            "link": "http://een.link",
            "beschrijving": "test_beschrijving",
            "informatieobjecttype":
            f"http://testserver{informatieobjecttype_url}",
            "vertrouwelijkheidaanduiding": "openbaar",
        }

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

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

        error = get_validation_errors(response, "inhoud")

        self.assertEqual(error["code"], "invalid")
Example #7
0
    def test_create_bio_fail_invalid_schema(self):
        base = "https://external.documenten.nl/api/v1/"
        document = f"{base}enkelvoudiginformatieobjecten/{uuid.uuid4()}"
        besluit = BesluitFactory.create(besluittype__concept=False)
        besluit_url = f"http://openzaak.nl{reverse(besluit)}"
        informatieobjecttype = InformatieObjectTypeFactory.create(
            catalogus=besluit.besluittype.catalogus, concept=False)
        informatieobjecttype_url = f"http://openzaak.nl{reverse(informatieobjecttype)}"
        informatieobjecttype.besluittypen.add(besluit.besluittype)

        with requests_mock.Mocker(real_http=True) as m:
            m.get(
                document,
                json={
                    "url": document,
                    "beschrijving": "",
                    "ontvangstdatum": None,
                    "informatieobjecttype": informatieobjecttype_url,
                    "locked": False,
                },
            )

            response = self.client.post(
                self.list_url,
                {
                    "besluit": besluit_url,
                    "informatieobject": document
                },
            )

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

        error = get_validation_errors(response, "informatieobject")
        self.assertEqual(error["code"], "invalid-resource")
    def _create_enkelvoudiginformatieobject(self, **HEADERS):
        informatieobjecttype = InformatieObjectTypeFactory.create(
            concept=False)
        informatieobjecttype_url = reverse(informatieobjecttype)
        content = {
            "identificatie": uuid.uuid4().hex,
            "bronorganisatie": "159351741",
            "creatiedatum": "2018-06-27",
            "titel": "detailed summary",
            "auteur": "test_auteur",
            "formaat": "txt",
            "taal": "eng",
            "bestandsnaam": "dummy.txt",
            "inhoud": b64encode(b"some file content").decode("utf-8"),
            "link": "http://een.link",
            "beschrijving": "test_beschrijving",
            "informatieobjecttype":
            f"http://testserver{informatieobjecttype_url}",
            "vertrouwelijkheidaanduiding": "openbaar",
        }

        response = self.client.post(self.informatieobject_list_url, content,
                                    **HEADERS)

        return response.data
    def test_destroy_with_external_informatieobject(self):
        oio = f"{self.base}objectinformatieobjecten/{uuid.uuid4()}"
        informatieobjecttype = InformatieObjectTypeFactory.create()

        with requests_mock.Mocker(real_http=True) as m:
            m.get(
                self.document,
                json=get_eio_response(
                    self.document,
                    informatieobjecttype=f"http://openzaak.nl{reverse(informatieobjecttype)}",
                ),
            )
            m.delete(oio)

            zio = ZaakInformatieObjectFactory.create(
                informatieobject=self.document, _objectinformatieobject_url=oio
            )
            zio_url = reverse(zio)

            response = self.client.delete(zio_url, HTTP_HOST="openzaak.nl")

        self.assertEqual(
            response.status_code, status.HTTP_204_NO_CONTENT, response.data
        )
        self.assertEqual(ZaakInformatieObject.objects.count(), 0)

        history_delete = [
            req
            for req in m.request_history
            if req.method == "DELETE" and req.url == oio
        ]
        self.assertEqual(len(history_delete), 1)
Example #10
0
    def setUpTestData(cls):
        cls.informatieobjecttype = InformatieObjectTypeFactory.create()

        site = Site.objects.get_current()
        site.domain = "testserver"
        site.save()

        super().setUpTestData()
    def test_add_autorisatie_all_current_informatieobjecttypen(self):
        iot1 = InformatieObjectTypeFactory.create(concept=False)
        iot2 = InformatieObjectTypeFactory.create(concept=True)

        data = {
            # management form
            "form-TOTAL_FORMS": 1,
            "form-INITIAL_FORMS": 0,
            "form-MIN_NUM_FORMS": 0,
            "form-MAX_NUM_FORMS": 1000,
            "form-0-component": ComponentTypes.drc,
            "form-0-scopes": ["documenten.lezen"],
            "form-0-related_type_selection": RelatedTypeSelectionMethods.all_current,
            "form-0-vertrouwelijkheidaanduiding": VertrouwelijkheidsAanduiding.beperkt_openbaar,
        }

        response = self.client.post(self.url, data)

        self.assertEqual(response.status_code, 302)
        self.assertEqual(Autorisatie.objects.count(), 2)
        self.assertEqual(self.applicatie.autorisaties.count(), 2)

        urls = [
            reverse(
                "informatieobjecttype-detail", kwargs={"version": 1, "uuid": iot1.uuid}
            ),
            reverse(
                "informatieobjecttype-detail", kwargs={"version": 1, "uuid": iot2.uuid}
            ),
        ]

        for autorisatie in Autorisatie.objects.all():
            with self.subTest(autorisatie=autorisatie):
                self.assertEqual(autorisatie.component, ComponentTypes.drc)
                self.assertEqual(autorisatie.scopes, ["documenten.lezen"])
                self.assertEqual(
                    autorisatie.max_vertrouwelijkheidaanduiding,
                    VertrouwelijkheidsAanduiding.beperkt_openbaar,
                )
                self.assertIsInstance(autorisatie.informatieobjecttype, str)
                parsed = urlparse(autorisatie.informatieobjecttype)
                self.assertEqual(parsed.scheme, "http")
                self.assertEqual(parsed.netloc, "testserver")
                self.assertIn(parsed.path, urls)
    def test_noop_all_current_and_future_besluittypen(self):
        bt = BesluitTypeFactory.create()
        Autorisatie.objects.create(
            applicatie=self.applicatie,
            component=ComponentTypes.brc,
            scopes=["besluiten.lezen"],
            informatieobjecttype=
            f"http://testserver{bt.get_absolute_api_url()}",
            max_vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.
            beperkt_openbaar,
        )
        data = {
            # management form
            "form-TOTAL_FORMS":
            1,
            "form-INITIAL_FORMS":
            0,
            "form-MIN_NUM_FORMS":
            0,
            "form-MAX_NUM_FORMS":
            1000,
            "form-0-component":
            ComponentTypes.brc,
            "form-0-scopes": ["besluiten.lezen"],
            "form-0-related_type_selection":
            RelatedTypeSelectionMethods.all_current_and_future,
        }

        response = self.client.post(self.url, data)

        self.assertEqual(response.status_code, 302)
        self.assertEqual(self.applicatie.autorisaties.count(), 1)

        # create a InformatieObjectType - this should trigger a new autorisatie
        # being installed
        BesluitTypeFactory.create()
        self.assertEqual(self.applicatie.autorisaties.count(), 2)

        # creating other types should not trigger anything, nor error
        ZaakTypeFactory.create()
        InformatieObjectTypeFactory.create()
        self.assertEqual(self.applicatie.autorisaties.count(), 2)
Example #13
0
    def test_eio_create_fail_send_notification_create_db_entry(self):
        url = get_operation_url("enkelvoudiginformatieobject_create")

        informatieobjecttype = InformatieObjectTypeFactory.create(
            concept=False)
        informatieobjecttype_url = reverse(informatieobjecttype)
        data = {
            "identificatie": uuid.uuid4().hex,
            "bronorganisatie": "159351741",
            "creatiedatum": "2018-06-27",
            "titel": "detailed summary",
            "auteur": "test_auteur",
            "formaat": "txt",
            "taal": "eng",
            "bestandsnaam": "dummy.txt",
            "inhoud": base64.b64encode(b"some file content").decode("utf-8"),
            "link": "http://een.link",
            "beschrijving": "test_beschrijving",
            "informatieobjecttype":
            f"http://testserver{informatieobjecttype_url}",
            "vertrouwelijkheidaanduiding": "openbaar",
        }

        with capture_on_commit_callbacks(execute=True):
            response = self.client.post(url, data)

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

        data = response.json()

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

        logged_warning = StatusLog.objects.get()
        failed = FailedNotification.objects.get()

        message = {
            "aanmaakdatum": "2019-01-01T12:00:00Z",
            "actie": "create",
            "hoofdObject": data["url"],
            "kanaal": "documenten",
            "kenmerken": {
                "bronorganisatie": "159351741",
                "informatieobjecttype":
                f"http://testserver{informatieobjecttype_url}",
                "vertrouwelijkheidaanduiding": "openbaar",
            },
            "resource": "enkelvoudiginformatieobject",
            "resourceUrl": data["url"],
        }

        self.assertEqual(failed.statuslog_ptr, logged_warning)
        self.assertEqual(failed.message, message)
    def test_add_autorisatie_all_current_and_future_informatieobjecttypen(self):
        data = {
            # management form
            "form-TOTAL_FORMS": 1,
            "form-INITIAL_FORMS": 0,
            "form-MIN_NUM_FORMS": 0,
            "form-MAX_NUM_FORMS": 1000,
            "form-0-component": ComponentTypes.drc,
            "form-0-scopes": ["documenten.lezen"],
            "form-0-related_type_selection": RelatedTypeSelectionMethods.all_current_and_future,
            "form-0-vertrouwelijkheidaanduiding": VertrouwelijkheidsAanduiding.beperkt_openbaar,
        }

        response = self.client.post(self.url, data)

        self.assertEqual(response.status_code, 302)
        self.assertFalse(Autorisatie.objects.exists())

        # create a informatieobjecttype - this should trigger a new autorisatie being installed
        InformatieObjectTypeFactory.create()
        self.assertEqual(self.applicatie.autorisaties.count(), 1)
Example #15
0
    def test_send_notif_create_enkelvoudiginformatieobject(self, mock_client):
        """
        Registreer een ENKELVOUDIGINFORMATIEOBJECT
        """
        informatieobjecttype = InformatieObjectTypeFactory.create(
            concept=False)
        informatieobjecttype_url = reverse(informatieobjecttype)
        client = mock_client.return_value
        url = get_operation_url("enkelvoudiginformatieobject_create")
        data = {
            "identificatie": "AMS20180701001",
            "bronorganisatie": "159351741",
            "creatiedatum": "2018-07-01",
            "titel": "text_extra.txt",
            "auteur": "ANONIEM",
            "formaat": "text/plain",
            "taal": "dut",
            "inhoud":
            base64.b64encode(b"Extra tekst in bijlage").decode("utf-8"),
            "informatieobjecttype":
            f"http://testserver{informatieobjecttype_url}",
            "vertrouwelijkheidaanduiding":
            VertrouwelijkheidsAanduiding.openbaar,
        }

        with capture_on_commit_callbacks(execute=True):
            response = self.client.post(url, data)

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

        data = response.json()
        client.create.assert_called_once_with(
            "notificaties",
            {
                "kanaal": "documenten",
                "hoofdObject": data["url"],
                "resource": "enkelvoudiginformatieobject",
                "resourceUrl": data["url"],
                "actie": "create",
                "aanmaakdatum": "2012-01-14T00:00:00Z",
                "kenmerken": {
                    "bronorganisatie":
                    "159351741",
                    "informatieobjecttype":
                    f"http://testserver{informatieobjecttype_url}",
                    "vertrouwelijkheidaanduiding":
                    VertrouwelijkheidsAanduiding.openbaar,
                },
            },
        )
Example #16
0
    def test_create_document_with_binary_content(self):
        informatieobjecttype = InformatieObjectTypeFactory.create(
            concept=False)
        informatieobjecttype_url = reverse(informatieobjecttype)
        content = {
            "identificatie":
            uuid.uuid4().hex,
            "bronorganisatie":
            "159351741",
            "creatiedatum":
            "2018-06-27",
            "titel":
            "detailed summary",
            "auteur":
            "test_auteur",
            "formaat":
            "txt",
            "taal":
            "eng",
            "bestandsnaam":
            "dummy.txt",
            "inhoud":
            b64encode(
                b"%PDF-1.4\n%\xc3\xa4\xc3\xbc\xc3\xb6\n2 0 obj\n<</Length 3 0 R/Filter/FlateDecode>>\nstream\nx\x9c"
            ).decode("utf-8"),
            "link":
            "http://een.link",
            "beschrijving":
            "test_beschrijving",
            "informatieobjecttype":
            f"http://testserver{informatieobjecttype_url}",
            "vertrouwelijkheidaanduiding":
            "openbaar",
        }

        # 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 storage backend (Alfresco)
        self.assertEqual(EnkelvoudigInformatieObject.objects.count(), 1)
        stored_object = EnkelvoudigInformatieObject.objects.get()

        self.assertEqual(
            stored_object.inhoud.read(),
            b"%PDF-1.4\n%\xc3\xa4\xc3\xbc\xc3\xb6\n2 0 obj\n<</Length 3 0 R/Filter/FlateDecode>>\nstream\nx\x9c",
        )
    def test_bio_visibility_outside_transaction(self):
        self.setUpTestData()
        document = f"{self.base}enkelvoudiginformatieobjecten/{uuid.uuid4()}"

        besluit = BesluitFactory.create(besluittype__concept=False)
        besluit_url = f"http://openzaak.nl{reverse(besluit)}"
        informatieobjecttype = InformatieObjectTypeFactory.create(
            catalogus=besluit.besluittype.catalogus, concept=False
        )
        informatieobjecttype_url = f"http://openzaak.nl{reverse(informatieobjecttype)}"
        informatieobjecttype.besluittypen.add(besluit.besluittype)
        eio_response = get_eio_response(
            document, informatieobjecttype=informatieobjecttype_url
        )

        def worker(besluit_id: int):
            """
            Worker to run in a thread.

            When this worker runs, there should be one ZIO visible in the database - it
            must have been committed so that the remote DRC can view this record too.
            """
            bios = BesluitInformatieObject.objects.filter(besluit__id=besluit_id)
            self.assertEqual(bios.count(), 1)
            close_old_connections()

        def mock_create_remote_oio(*args, **kwargs):
            with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
                future = executor.submit(worker, besluit.id)
                future.result()  # raises any exceptions, such as assertionerrors
            return {"url": f"{self.base}objectinformatieobjecten/{uuid.uuid4()}"}

        with patch(
            "openzaak.components.besluiten.api.serializers.create_remote_oio",
            side_effect=mock_create_remote_oio,
        ):
            with requests_mock.Mocker() as m:
                mock_service_oas_get(
                    m, APITypes.drc, self.base, oas_url=settings.DRC_API_SPEC
                )
                m.get(document, json=eio_response)

                response = self.client.post(
                    self.list_url,
                    {"besluit": besluit_url, "informatieobject": document},
                )

        self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data)
Example #18
0
    def test_validate_informatieobjecttype_unpublished(self):
        informatieobjecttype = InformatieObjectTypeFactory.create()
        informatieobjecttype_url = reverse(informatieobjecttype)
        url = reverse("enkelvoudiginformatieobject-list")

        response = self.client.post(
            url,
            {
                "informatieobjecttype":
                f"http://testserver{informatieobjecttype_url}"
            },
        )

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        error = get_validation_errors(response, "informatieobjecttype")
        self.assertEqual(error["code"], "not-published")
Example #19
0
    def test_update_informatieobjecttype_fails(self):
        eio = EnkelvoudigInformatieObjectFactory.create()
        eio_url = reverse(eio)

        iotype = InformatieObjectTypeFactory.create()
        iotype_url = reverse(iotype)

        response = self.client.patch(
            eio_url,
            {"informatieobjecttype": f"http://testserver{iotype_url}"})

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

        error = get_validation_errors(response, "informatieobjecttype")
        self.assertEqual(error["code"], IsImmutableValidator.code)
    def test_inline_informatieobjecttype_autorisaties(self):
        iot = InformatieObjectTypeFactory.create()
        self._add_autorisatie(
            iot,
            component=ComponentTypes.drc,
            scopes=["documenten.lezen"],
            max_vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.geheim,
        )

        response = self.app.get(self.url)

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, str(iot))
        self.assertContains(
            response,
            VertrouwelijkheidsAanduiding.labels[VertrouwelijkheidsAanduiding.geheim],
        )
Example #21
0
    def test_vertrouwelijkheidaanduiding_derived(self):
        """
        Assert that the default vertrouwelijkheidaanduiding is set
        from informatieobjecttype
        """
        informatieobjecttype = InformatieObjectTypeFactory.create(
            vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.
            zaakvertrouwelijk,
            concept=False,
        )
        informatieobjecttype_url = reverse(informatieobjecttype)
        url = reverse("enkelvoudiginformatieobject-list")

        response = self.client.post(
            url,
            {
                "bronorganisatie":
                "159351741",
                "creatiedatum":
                "2018-06-27",
                "titel":
                "detailed summary",
                "auteur":
                "test_auteur",
                "formaat":
                "txt",
                "taal":
                "eng",
                "bestandsnaam":
                "dummy.txt",
                "inhoud":
                b64encode(b"some file content").decode("utf-8"),
                "link":
                "http://een.link",
                "beschrijving":
                "test_beschrijving",
                "informatieobjecttype":
                f"http://testserver{informatieobjecttype_url}",
            },
        )

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(
            response.data["vertrouwelijkheidaanduiding"],
            VertrouwelijkheidsAanduiding.zaakvertrouwelijk,
        )
Example #22
0
    def setUpTestData(cls):
        cls.informatieobjecttype = InformatieObjectTypeFactory.create()

        site = Site.objects.get_current()
        site.domain = "testserver"
        site.save()

        if settings.CMIS_URL_MAPPING_ENABLED:
            config = CMISConfig.objects.get()

            UrlMapping.objects.create(
                long_pattern="https://externe.catalogus.nl",
                short_pattern="https://xcat.nl",
                config=config,
            )

        super().setUpTestData()
    def test_create_fail_informatieobjecttype_max_length(self):
        informatieobjecttype = InformatieObjectTypeFactory.create()
        informatieobjecttype_url = reverse(informatieobjecttype)
        content = {
            "identificatie":
            uuid.uuid4().hex,
            "bronorganisatie":
            "159351741",
            "creatiedatum":
            "2018-06-27",
            "titel":
            "detailed summary",
            "auteur":
            "test_auteur",
            "formaat":
            "txt",
            "taal":
            "eng",
            "bestandsnaam":
            "dummy.txt",
            "inhoud":
            b64encode(b"some file content").decode("utf-8"),
            "link":
            "http://een.link",
            "beschrijving":
            "test_beschrijving",
            "informatieobjecttype":
            f"http://testserver/some-very-long-url-addres-which-exceeds-maximum-"
            f"length-of-hyperlinkedrelatedfield/aaaaaaaaaaaaaaaaaaaaaaaaa/"
            f"{informatieobjecttype_url}",
            "vertrouwelijkheidaanduiding":
            "openbaar",
        }

        # 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, "informatieobjecttype")
        self.assertEqual(error["code"], "max_length")
    def test_create_enkelvoudiginformatieobject(self):
        """
        Registreer een ENKELVOUDIGINFORMATIEOBJECT
        """
        informatieobjecttype = InformatieObjectTypeFactory.create(
            concept=False)
        informatieobjecttype_url = reverse(informatieobjecttype)
        url = get_operation_url("enkelvoudiginformatieobject_create")
        data = {
            "identificatie": "AMS20180701001",
            "bronorganisatie": "159351741",
            "creatiedatum": "2018-07-01",
            "titel": "text_extra.txt",
            "auteur": "ANONIEM",
            "formaat": "text/plain",
            "taal": "dut",
            "inhoud":
            base64.b64encode(b"Extra tekst in bijlage").decode("utf-8"),
            "informatieobjecttype":
            f"http://testserver{informatieobjecttype_url}",
            "vertrouwelijkheidaanduiding":
            VertrouwelijkheidsAanduiding.openbaar,
        }

        response = self.client.post(url, data)

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

        eio = EnkelvoudigInformatieObject.objects.get()

        self.assertEqual(eio.identificatie, "AMS20180701001")
        self.assertEqual(eio.creatiedatum, date(2018, 7, 1))

        download_url = urlparse(response.data["inhoud"])

        self.assertEqual(
            download_url.path,
            get_operation_url("enkelvoudiginformatieobject_download",
                              uuid=eio.uuid),
        )
    def test_eio_add(self):
        informatieobjecttype = InformatieObjectTypeFactory.create()
        file = tempfile.NamedTemporaryFile()
        file.write(b"some content")
        file.seek(0)

        get_response = self.app.get(self.change_url)

        form = get_response.form
        form["enkelvoudiginformatieobject_set-0-identificatie"] = "12345"
        form["enkelvoudiginformatieobject_set-0-bronorganisatie"] = "517439943"
        form["enkelvoudiginformatieobject_set-0-creatiedatum"] = "18-11-2019"
        form["enkelvoudiginformatieobject_set-0-titel"] = "some titel"
        form["enkelvoudiginformatieobject_set-0-auteur"] = "some author"
        form[
            "enkelvoudiginformatieobject_set-0-_informatieobjecttype"] = informatieobjecttype.id
        form["enkelvoudiginformatieobject_set-0-taal"] = "Rus"
        form["enkelvoudiginformatieobject_set-0-inhoud"] = (file.name, )
        form["enkelvoudiginformatieobject_set-0-versie"] = "1"
        form.submit()

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

        eio = EnkelvoudigInformatieObject.objects.get()
        eio_url = get_operation_url("enkelvoudiginformatieobject_read",
                                    uuid=eio.uuid)
        audittrail = AuditTrail.objects.get()

        self.assertEioAudittrail(audittrail)
        self.assertEqual(audittrail.actie, "create")
        self.assertEqual(audittrail.resource, "enkelvoudiginformatieobject"),
        self.assertEqual(audittrail.resource_url,
                         f"http://testserver{eio_url}"),
        self.assertEqual(audittrail.resource_weergave,
                         eio.unique_representation())
        self.assertEqual(audittrail.hoofd_object,
                         f"http://testserver{eio_url}"),
        self.assertEqual(audittrail.oud, None)

        new_data = audittrail.nieuw
        self.assertEqual(new_data["identificatie"], "12345")
Example #26
0
    def test_create_informatieobject_save(self):
        informatieobjecttype = InformatieObjectTypeFactory.create(
            concept=False)
        canonical = EnkelvoudigInformatieObjectCanonicalFactory.create(
            latest_version=None)
        add_url = reverse("admin:documenten_enkelvoudiginformatieobject_add")

        response = self.app.get(add_url)
        form = response.form

        form["canonical"] = canonical.pk
        form["bronorganisatie"] = "000000000"
        form["creatiedatum"] = "2010-01-01"
        form["_informatieobjecttype"] = informatieobjecttype.pk
        form["titel"] = "test"
        form["auteur"] = "test"
        form["taal"] = "nld"
        form["inhoud"] = Upload("stuff.txt", b"")

        response = form.submit(name="_continue")
        self.assertEqual(response.status_code, 200)
Example #27
0
    def test_create_eio_is_forbidden_when_cmis_enabled(self):
        informatieobjecttype = InformatieObjectTypeFactory.create(
            concept=False)
        informatieobjecttype_url = tests.reverse(informatieobjecttype)

        add_url = reverse("admin:documenten_enkelvoudiginformatieobject_add")

        data = {
            "uuid": uuid.uuid4(),
            "informatieobjecttype": informatieobjecttype_url,
            "bronorganisatie": "517439943",
            "creatiedatum": "15-11-2019",
            "titel": "detailed summary",
            "auteur": "test_auteur",
            "formaat": "txt",
            "taal": "eng",
            "bestandsnaam": "dummy.txt",
            "beschrijving": "desc",
            "versie": 1,
        }

        response = self.client.post(add_url, data)
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Example #28
0
    def test_informatieobject_create(self):
        eio_url = reverse(EnkelvoudigInformatieObject)
        informatieobjecttype = InformatieObjectTypeFactory.create(concept=True)
        informatieobjecttype_url = reverse(informatieobjecttype)
        content = {
            "bronorganisatie": "159351741",
            "creatiedatum": "2018-06-27",
            "titel": "detailed summary",
            "auteur": "test_auteur",
            "formaat": "txt",
            "taal": "eng",
            "bestandsnaam": "dummy.txt",
            "inhoud": b64encode(b"some file content").decode("utf-8"),
            "link": "http://een.link",
            "beschrijving": "test_beschrijving",
            "informatieobjecttype": f"http://testserver{informatieobjecttype_url}",
            "vertrouwelijkheidaanduiding": "openbaar",
        }

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

        # Test response
        self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data)
    def test_page_returns_on_get(self):
        # set up some initial data
        iot = InformatieObjectTypeFactory.create()
        Autorisatie.objects.create(
            applicatie=self.applicatie,
            component=ComponentTypes.drc,
            scopes=["documenten.lezen"],
            max_vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.openbaar,
            informatieobjecttype=build_absolute_url(iot.get_absolute_api_url()),
        )
        AutorisatieSpecFactory.create(
            applicatie=self.applicatie,
            component=ComponentTypes.brc,
            scopes=["besluiten.lezen"],
        )
        Autorisatie.objects.create(
            applicatie=self.applicatie,
            component=ComponentTypes.nrc,
            scopes=["notificaties.consumeren"],
        )

        response = self.client.get(self.url)

        self.assertEqual(response.status_code, 200)
    def test_create(self):
        informatieobjecttype = InformatieObjectTypeFactory.create(
            concept=False)
        informatieobjecttype_url = reverse(informatieobjecttype)
        content = {
            "identificatie": uuid.uuid4().hex,
            "bronorganisatie": "159351741",
            "creatiedatum": "2018-06-27",
            "titel": "detailed summary",
            "auteur": "test_auteur",
            "formaat": "txt",
            "taal": "eng",
            "bestandsnaam": "dummy.txt",
            "inhoud": b64encode(b"some file content").decode("utf-8"),
            "link": "http://een.link",
            "beschrijving": "test_beschrijving",
            "informatieobjecttype":
            f"http://testserver{informatieobjecttype_url}",
            "vertrouwelijkheidaanduiding": "openbaar",
        }

        # 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(EnkelvoudigInformatieObject.objects.count(), 1)
        stored_object = EnkelvoudigInformatieObject.objects.get()

        self.assertEqual(stored_object.identificatie, content["identificatie"])
        self.assertEqual(stored_object.bronorganisatie, "159351741")
        self.assertEqual(stored_object.creatiedatum, date(2018, 6, 27))
        self.assertEqual(stored_object.titel, "detailed summary")
        self.assertEqual(stored_object.auteur, "test_auteur")
        self.assertEqual(stored_object.formaat, "txt")
        self.assertEqual(stored_object.taal, "eng")
        self.assertEqual(stored_object.versie, 1)
        self.assertAlmostEqual(stored_object.begin_registratie, timezone.now())
        self.assertEqual(stored_object.bestandsnaam, "dummy.txt")
        self.assertEqual(stored_object.inhoud.read(), b"some file content")
        self.assertEqual(stored_object.link, "http://een.link")
        self.assertEqual(stored_object.beschrijving, "test_beschrijving")
        self.assertEqual(stored_object.informatieobjecttype,
                         informatieobjecttype)
        self.assertEqual(stored_object.vertrouwelijkheidaanduiding, "openbaar")

        expected_url = reverse(stored_object)
        expected_file_url = get_operation_url(
            "enkelvoudiginformatieobject_download", uuid=stored_object.uuid)

        expected_response = content.copy()
        expected_response.update({
            "url":
            f"http://testserver{expected_url}",
            "inhoud":
            f"http://testserver{expected_file_url}?versie=1",
            "versie":
            1,
            "beginRegistratie":
            stored_object.begin_registratie.isoformat().replace("+00:00", "Z"),
            "vertrouwelijkheidaanduiding":
            "openbaar",
            "bestandsomvang":
            stored_object.inhoud.size,
            "integriteit": {
                "algoritme": "",
                "waarde": "",
                "datum": None
            },
            "ontvangstdatum":
            None,
            "verzenddatum":
            None,
            "ondertekening": {
                "soort": "",
                "datum": None
            },
            "indicatieGebruiksrecht":
            None,
            "status":
            "",
            "locked":
            False,
        })

        response_data = response.json()
        self.assertEqual(sorted(response_data.keys()),
                         sorted(expected_response.keys()))

        for key in response_data.keys():
            with self.subTest(field=key):
                self.assertEqual(response_data[key], expected_response[key])