def test_list_oio_limited_to_authorized_zaken(self):
        url = reverse('objectinformatieobject-list')
        # must show up
        oio1 = ObjectInformatieObjectFactory.create(
            informatieobject__latest_version__informatieobjecttype=
            'https://informatieobjecttype.nl/ok',
            informatieobject__latest_version__vertrouwelijkheidaanduiding=
            VertrouwelijkheidsAanduiding.openbaar,
            is_zaak=True)
        # must not show up
        ObjectInformatieObjectFactory.create(
            informatieobject__latest_version__informatieobjecttype=
            'https://informatieobjecttype.nl/ok',
            informatieobject__latest_version__vertrouwelijkheidaanduiding=
            VertrouwelijkheidsAanduiding.vertrouwelijk,
            is_zaak=True)
        # must not show up
        ObjectInformatieObjectFactory.create(
            informatieobject__latest_version__informatieobjecttype=
            'https://informatieobjecttype.nl/not_ok',
            informatieobject__latest_version__vertrouwelijkheidaanduiding=
            VertrouwelijkheidsAanduiding.openbaar,
            is_zaak=True)

        response = self.client.get(url)

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

        response_data = response.json()

        self.assertEqual(len(response_data), 1)
        self.assertEqual(response_data[0]['url'],
                         f"http://testserver{reverse(oio1)}")
    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)
Esempio n. 3
0
    def test_detail_oio_limited_to_authorized_zaken(self):
        # must show up
        oio1 = ObjectInformatieObjectFactory.create(
            informatieobject__latest_version__informatieobjecttype=
            "https://informatieobjecttype.nl/ok",
            informatieobject__latest_version__vertrouwelijkheidaanduiding=
            VertrouwelijkheidsAanduiding.openbaar,
            is_zaak=True,
        )
        # must not show up
        oio2 = ObjectInformatieObjectFactory.create(
            informatieobject__latest_version__informatieobjecttype=
            "https://informatieobjecttype.nl/ok",
            informatieobject__latest_version__vertrouwelijkheidaanduiding=
            VertrouwelijkheidsAanduiding.vertrouwelijk,
            is_zaak=True,
        )
        # must not show up
        oio3 = ObjectInformatieObjectFactory.create(
            informatieobject__latest_version__informatieobjecttype=
            "https://informatieobjecttype.nl/not_ok",
            informatieobject__latest_version__vertrouwelijkheidaanduiding=
            VertrouwelijkheidsAanduiding.openbaar,
            is_zaak=True,
        )

        with self.subTest(
                informatieobjecttype=oio1.informatieobject.latest_version.
                informatieobjecttype,
                vertrouwelijkheidaanduiding=oio1.informatieobject.
                latest_version.vertrouwelijkheidaanduiding,
        ):
            url = reverse(oio1)

            response = self.client.get(url)

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

        # not allowed to see these
        for oio in (oio2, oio3):
            with self.subTest(
                    informatieobjecttype=oio.informatieobject.latest_version.
                    informatieobjecttype,
                    vertrouwelijkheidaanduiding=oio.informatieobject.
                    latest_version.vertrouwelijkheidaanduiding,
            ):
                url = reverse(oio)

                response = self.client.get(url)

                self.assertEqual(response.status_code,
                                 status.HTTP_403_FORBIDDEN)
    def test_destroy_with_relations_not_allowed(self):
        """
        Assert that destroying is not possible when there are relations.
        """
        eio = EnkelvoudigInformatieObjectFactory.create()
        ObjectInformatieObjectFactory.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")
    def test_update_zaak(self):
        eo = EnkelvoudigInformatieObjectFactory.create()
        zio = ObjectInformatieObjectFactory.create(is_zaak=True)

        eo_detail_url = reverse('enkelvoudiginformatieobject-detail',
                                kwargs={
                                    'version': '1',
                                    'uuid': eo.uuid,
                                })
        zio_detail_url = reverse('objectinformatieobject-detail',
                                 kwargs={
                                     'version': '1',
                                     'uuid': zio.uuid,
                                 })

        response = self.client.patch(
            zio_detail_url, {
                'object': 'https://something.different',
                'informatieobject': eo_detail_url,
                'objectType': ObjectTypes.besluit,
            })

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

        for field in ['object', 'informatieobject', 'objectType']:
            with self.subTest(field=field):
                error = get_validation_errors(response, field)
                self.assertEqual(error['code'], IsImmutableValidator.code)
    def test_read_zaak(self):
        zio = ObjectInformatieObjectFactory.create(is_zaak=True)
        # Retrieve from the API

        zio_detail_url = reverse('objectinformatieobject-detail',
                                 kwargs={
                                     'version': '1',
                                     'uuid': zio.uuid,
                                 })
        response = self.client.get(zio_detail_url)

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

        eo_detail_url = reverse('enkelvoudiginformatieobject-detail',
                                kwargs={
                                    'version': '1',
                                    'uuid': zio.informatieobject.uuid,
                                })

        expected = {
            'url': f'http://testserver{zio_detail_url}',
            'informatieobject': f'http://testserver{eo_detail_url}',
            'object': zio.object,
            'objectType': ObjectTypes.zaak,
            'aardRelatieWeergave':
            RelatieAarden.labels[RelatieAarden.hoort_bij],
            'titel': '',
            'beschrijving': '',
            'registratiedatum': dt_to_api(zio.registratiedatum),
        }

        self.assertEqual(response.json(), expected)
    def test_duplicate_object(self):
        """
        Test the (informatieobject, object) unique together validation.
        """
        oio = ObjectInformatieObjectFactory.create(is_zaak=True)
        enkelvoudig_informatie_url = reverse(
            'enkelvoudiginformatieobject-detail',
            kwargs={
                'version': '1',
                'uuid': oio.informatieobject.uuid,
            })

        content = {
            'informatieobject':
            f'http://testserver{enkelvoudig_informatie_url}',
            'object': oio.object,
            'objectType': ObjectTypes.zaak,
        }

        # 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_conditional_get_stale(self):
        oio = ObjectInformatieObjectFactory.create(with_etag=True)

        response = self.client.get(reverse(oio),
                                   HTTP_IF_NONE_MATCH=f'"not-an-md5"')

        self.assertEqual(response.status_code, status.HTTP_200_OK)
    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)
        ObjectInformatieObjectFactory.create(is_zaak=True, object='http://www.example.com/zrc/api/v1/zaken/2')

        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)
    def test_destroy_oio_remote_gone(self, mock_fetch_schema, mock_get_operation_url):
        mock_get_operation_url.return_value = '/api/v1/zaakinformatieobjecten'
        oio = ObjectInformatieObjectFactory.create(is_zaak=True, object=ZAAK)
        url = reverse(oio)

        with mock_client(responses=self.RESPONSES):
            response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        self.assertFalse(ObjectInformatieObject.objects.exists())
    def test_destroy_oio_remote_still_present(self, mock_fetch_schema, mock_get_operation_url):
        mock_get_operation_url.return_value = '/api/v1/besluitinformatieobjecten'
        oio = ObjectInformatieObjectFactory.create(is_besluit=True, object=BESLUIT)
        url = reverse(oio)

        with mock_client(responses=self.RESPONSES):
            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"], "remote-relation-exists")
    def test_delete_document_cascades_properly(self):
        """
        Deleting a EnkelvoudigInformatieObject causes all related objects to be deleted as well.
        """
        informatieobject = EnkelvoudigInformatieObjectFactory.create()

        GebruiksrechtenFactory.create(informatieobject=informatieobject)
        ObjectInformatieObjectFactory.create(informatieobject=informatieobject,
                                             is_zaak=True)

        informatieobject_delete_url = get_operation_url(
            'enkelvoudiginformatieobject_delete', uuid=informatieobject.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())
        self.assertFalse(ObjectInformatieObject.objects.all().exists())
Esempio n. 13
0
    def test_filter(self):
        zio = ObjectInformatieObjectFactory.create(is_zaak=True)
        eo_detail_url = reverse('enkelvoudiginformatieobject-detail', kwargs={
            'version': '1',
            'uuid': zio.informatieobject.uuid,
        })
        zio_list_url = reverse('objectinformatieobject-list', kwargs={'version': '1'})

        response = self.client.get(zio_list_url, {
            'informatieobject': f'http://testserver{eo_detail_url}',
        })

        self.assertEqual(response.status_code, 200)
    def test_filter(self):
        oio = ObjectInformatieObjectFactory.create(
            is_zaak=True,
        )
        eo_detail_url = reverse('enkelvoudiginformatieobject-detail', kwargs={
            'uuid': oio.informatieobject.latest_version.uuid
        })

        response = self.client.get(self.list_url, {
            'informatieobject': f'http://testserver{eo_detail_url}',
        })

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['informatieobject'], f'http://testserver{eo_detail_url}')
Esempio n. 15
0
    def test_cannot_read_without_correct_scope(self):
        eio = EnkelvoudigInformatieObjectFactory.create()
        gebruiksrechten = GebruiksrechtenFactory.create()
        oio = ObjectInformatieObjectFactory.create(is_besluit=True)
        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_filter(self):
        oio = ObjectInformatieObjectFactory.create(is_zaak=True)
        eo_detail_url = reverse(
            "enkelvoudiginformatieobject-detail",
            kwargs={"uuid": oio.informatieobject.latest_version.uuid},
        )

        response = self.client.get(
            self.list_url,
            {"informatieobject": f"http://testserver.com{eo_detail_url}"},
            HTTP_HOST="testserver.com",
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(
            response.data[0]["informatieobject"],
            f"http://testserver.com{eo_detail_url}",
        )
    def test_duplicate_object(self, *mocks):
        """
        Test the (informatieobject, object) unique together validation.
        """
        oio = ObjectInformatieObjectFactory.create(is_zaak=True)
        enkelvoudig_informatie_url = reverse(
            "enkelvoudiginformatieobject-detail",
            kwargs={"uuid": oio.informatieobject.latest_version.uuid},
        )

        content = {
            "informatieobject":
            f"http://testserver{enkelvoudig_informatie_url}",
            "object": oio.object,
            "objectType": ObjectTypes.zaak,
        }

        # 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_delete(self):
        document = EnkelvoudigInformatieObjectFactory.create()
        oio = ObjectInformatieObjectFactory.create(
            informatieobject=document,
            object=ZAAK,
            object_type=ObjectTypes.zaak,
            aard_relatie=RelatieAarden.hoort_bij)
        oio_url = reverse('objectinformatieobject-detail',
                          kwargs={
                              'version': '1',
                              'uuid': oio.uuid,
                          })

        self.assertEqual(self.mocked_sync_delete.call_count, 0)

        response = self.client.delete(oio_url)
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT,
                         response.data)

        self.assertEqual(self.mocked_sync_delete.call_count, 1)

        # Relation is gone, document still exists.
        self.assertFalse(ObjectInformatieObject.objects.exists())
        self.assertTrue(EnkelvoudigInformatieObject.objects.exists())
    def test_conditional_get_304(self):
        oio = ObjectInformatieObjectFactory.create(with_etag=True)
        response = self.client.get(reverse(oio),
                                   HTTP_IF_NONE_MATCH=f'"{oio._etag}"')

        self.assertEqual(response.status_code, status.HTTP_304_NOT_MODIFIED)
    def test_oio_head_cache_header(self):
        oio = ObjectInformatieObjectFactory.create()

        self.assertHeadHasETag(reverse(oio))
    def test_oio_get_cache_header(self):
        oio = ObjectInformatieObjectFactory.create()

        response = self.client.get(reverse(oio))

        self.assertHasETag(response)