Пример #1
0
    def test_informatieobjecttype_filter(self):
        zaak_url = "http://www.example.com/zrc/api/v1/zaken/1"

        ObjectInformatieObjectFactory.create_batch(
            2,
            is_zaak=True,
            object=zaak_url,
            informatieobject__latest_version__informatieobjecttype=
            INFORMATIEOBJECTTYPE,
        )
        ObjectInformatieObjectFactory.create(
            is_zaak=True,
            object="http://www.example.com/zrc/api/v1/zaken/2",
            informatieobject__latest_version__informatieobjecttype=
            INFORMATIEOBJECTTYPE,
        )

        url = get_operation_url("objectinformatieobject_list")

        response = self.client.get(url, {"object": zaak_url})

        self.assertEqual(response.status_code, status.HTTP_200_OK,
                         response.json())

        response_data = response.json()
        self.assertEqual(len(response_data), 2)

        for zio in response_data:
            self.assertEqual(zio["object"], zaak_url)
Пример #2
0
    def test_create_ignores_lock(self):
        informatieobjecttype = InformatieObjectTypeFactory.create()
        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": 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)
Пример #3
0
    def test_list_file(self):
        eio = EnkelvoudigInformatieObjectCanonicalFactory.create()
        list_url = get_operation_url("enkelvoudiginformatieobject_list")

        response = self.client.get(list_url)

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

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

        self.assertEqual(
            download_url.path,
            get_operation_url("enkelvoudiginformatieobject_download",
                              uuid=eio.latest_version.uuid),
        )
Пример #4
0
    def test_read_detail_file(self):
        eio = EnkelvoudigInformatieObjectFactory.create()
        file_url = get_operation_url("enkelvoudiginformatieobject_download",
                                     uuid=eio.uuid)

        response = self.client.get(file_url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.content.decode("utf-8"), "some data")
Пример #5
0
    def test_create_enkelvoudiginformatieobject(self):
        """
        Registreer een ENKELVOUDIGINFORMATIEOBJECT
        """
        informatieobjecttype = InformatieObjectTypeFactory.create()
        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": 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.assertTrue(
            download_url.path,
            get_operation_url("enkelvoudiginformatieobject_download",
                              uuid=eio.uuid),
        )
Пример #6
0
    def test_update_success(self):
        lock = uuid.uuid4().hex
        eio = EnkelvoudigInformatieObjectCanonicalFactory.create(lock=lock)
        url = get_operation_url(
            "enkelvoudiginformatieobject_update", uuid=eio.latest_version.uuid
        )

        response = self.client.patch(url, {"titel": "changed", "lock": lock})

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

        eio.refresh_from_db()

        self.assertEqual(eio.latest_version.titel, "changed")
Пример #7
0
    def test_lock_fail_locked_doc(self):
        eio = EnkelvoudigInformatieObjectCanonicalFactory.create(lock=uuid.uuid4().hex)

        url = get_operation_url(
            "enkelvoudiginformatieobject_lock", uuid=eio.latest_version.uuid
        )
        response = self.client.post(url)

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

        error = get_validation_errors(response, "nonFieldErrors")
        self.assertEqual(error["code"], "existing-lock")
Пример #8
0
    def test_unlock_fail_incorrect_id(self):
        eio = EnkelvoudigInformatieObjectFactory.create(
            canonical__lock=uuid.uuid4().hex,
            informatieobjecttype=self.informatieobjecttype,
        )
        url = get_operation_url("enkelvoudiginformatieobject_unlock", uuid=eio.uuid)

        response = self.client.post(url)

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

        error = get_validation_errors(response, "nonFieldErrors")
        self.assertEqual(error["code"], "incorrect-lock-id")
Пример #9
0
    def test_update_fail_wrong_id(self):
        eio = EnkelvoudigInformatieObjectCanonicalFactory.create(lock=uuid.uuid4().hex)

        url = get_operation_url(
            "enkelvoudiginformatieobject_update", uuid=eio.latest_version.uuid
        )

        response = self.client.patch(url, {"titel": "changed", "lock": 12345})

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

        error = get_validation_errors(response, "nonFieldErrors")
        self.assertEqual(error["code"], "incorrect-lock-id")
    def test_send_notif_create_enkelvoudiginformatieobject(self, mock_client):
        """
        Registreer een ENKELVOUDIGINFORMATIEOBJECT
        """
        informatieobjecttype = InformatieObjectTypeFactory.create()
        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": informatieobjecttype_url,
            "vertrouwelijkheidaanduiding":
            VertrouwelijkheidsAanduiding.openbaar,
        }

        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,
                },
            },
        )
Пример #11
0
    def test_update_fail_unlocked_doc(self):
        eio = EnkelvoudigInformatieObjectCanonicalFactory.create()
        assert eio.lock == ""

        url = get_operation_url(
            "enkelvoudiginformatieobject_update", uuid=eio.latest_version.uuid
        )

        response = self.client.patch(url, {"titel": "changed"})

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

        error = get_validation_errors(response, "nonFieldErrors")
        self.assertEqual(error["code"], "unlocked")
Пример #12
0
    def test_lock_success(self):
        eio = EnkelvoudigInformatieObjectCanonicalFactory.create()
        assert eio.lock == ""
        url = get_operation_url(
            "enkelvoudiginformatieobject_lock", uuid=eio.latest_version.uuid
        )

        response = self.client.post(url)

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

        data = response.json()
        eio.refresh_from_db()

        self.assertEqual(data["lock"], eio.lock)
        self.assertNotEqual(data["lock"], "")
Пример #13
0
    def test_unlock_success(self):
        lock = uuid.uuid4().hex
        eio = EnkelvoudigInformatieObjectFactory.create(
            canonical__lock=lock, informatieobjecttype=self.informatieobjecttype
        )
        url = get_operation_url("enkelvoudiginformatieobject_unlock", uuid=eio.uuid)

        response = self.client.post(url, {"lock": lock})

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

        eio.refresh_from_db()

        self.assertEqual(eio.canonical.lock, "")
    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")
Пример #15
0
    def test_read(self):
        test_object = EnkelvoudigInformatieObjectFactory.create()
        # Retrieve from the API
        detail_url = reverse(test_object)

        response = self.client.get(detail_url)

        # Test response
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        file_url = get_operation_url(
            "enkelvoudiginformatieobject_download", uuid=test_object.uuid
        )
        expected = {
            "url": f"http://testserver{detail_url}",
            "identificatie": test_object.identificatie,
            "bronorganisatie": test_object.bronorganisatie,
            "creatiedatum": "2018-06-27",
            "titel": "some titel",
            "auteur": "some auteur",
            "status": "",
            "formaat": "some formaat",
            "taal": "nld",
            "beginRegistratie": test_object.begin_registratie.isoformat().replace(
                "+00:00", "Z"
            ),
            "versie": 1,
            "bestandsnaam": "",
            "inhoud": f"http://testserver{file_url}?versie=1",
            "bestandsomvang": test_object.inhoud.size,
            "link": "",
            "beschrijving": "",
            "ontvangstdatum": None,
            "verzenddatum": None,
            "ondertekening": {"soort": "", "datum": None},
            "indicatieGebruiksrecht": None,
            "vertrouwelijkheidaanduiding": "openbaar",
            "integriteit": {"algoritme": "", "waarde": "", "datum": None},
            "informatieobjecttype": f"http://testserver{reverse(test_object.informatieobjecttype)}",
            "locked": False,
        }
        response_data = response.json()
        self.assertEqual(sorted(response_data.keys()), sorted(expected.keys()))

        for key in response_data.keys():
            with self.subTest(field=key):
                self.assertEqual(response_data[key], expected[key])
Пример #16
0
    def test_unlock_force(self):
        self.autorisatie.scopes = [SCOPE_DOCUMENTEN_GEFORCEERD_UNLOCK]
        self.autorisatie.save()

        eio = EnkelvoudigInformatieObjectFactory.create(
            canonical__lock=uuid.uuid4().hex,
            informatieobjecttype=self.informatieobjecttype,
        )
        url = get_operation_url("enkelvoudiginformatieobject_unlock", uuid=eio.uuid)

        response = self.client.post(url)

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

        eio.refresh_from_db()

        self.assertEqual(eio.canonical.lock, "")
    def test_delete_document_cascades_properly(self):
        """
        Deleting a EnkelvoudigInformatieObject causes all related objects to be deleted as well.
        """
        informatieobject = EnkelvoudigInformatieObjectCanonicalFactory.create()

        GebruiksrechtenFactory.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_204_NO_CONTENT,
                         response.data)

        self.assertEqual(EnkelvoudigInformatieObject.objects.all().count(), 0)

        self.assertFalse(Gebruiksrechten.objects.all().exists())
Пример #18
0
    def test_create(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{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])