Ejemplo n.º 1
0
    def test_delete_besluit_cascades_properly(self):
        """
        Deleting a Besluit causes all related objects to be deleted as well.
        """
        besluit = BesluitFactory.create()
        BesluitInformatieObjectFactory.create(besluit=besluit)
        besluit_delete_url = get_operation_url("besluit_delete", uuid=besluit.uuid)

        response = self.client.delete(besluit_delete_url)

        self.assertEqual(
            response.status_code, status.HTTP_204_NO_CONTENT, response.data
        )
        self.assertFalse(Besluit.objects.exists())
        self.assertFalse(BesluitInformatieObject.objects.exists())
    def test_send_notif_delete_resultaat(self, mock_client):
        """
        Check if notifications will be send when resultaat is deleted
        """
        client = mock_client.return_value
        besluit = BesluitFactory.create()
        besluit_url = get_operation_url("besluit_read", uuid=besluit.uuid)
        besluittype_url = reverse(besluit.besluittype)
        bio = BesluitInformatieObjectFactory.create(besluit=besluit)
        bio_url = get_operation_url("besluitinformatieobject_delete",
                                    uuid=bio.uuid)

        response = self.client.delete(bio_url)

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

        client.create.assert_called_once_with(
            "notificaties",
            {
                "kanaal": "besluiten",
                "hoofdObject": f"http://testserver{besluit_url}",
                "resource": "besluitinformatieobject",
                "resourceUrl": f"http://testserver{bio_url}",
                "actie": "destroy",
                "aanmaakdatum": "2018-09-07T00:00:00Z",
                "kenmerken": {
                    "verantwoordelijkeOrganisatie":
                    besluit.verantwoordelijke_organisatie,
                    "besluittype": f"http://testserver{besluittype_url}",
                },
            },
        )
    def test_create_with_objecttype_besluit(self):
        besluit = BesluitFactory.create()
        eio = EnkelvoudigInformatieObjectFactory.create()
        # relate the two
        bio = BesluitInformatieObjectFactory.create(
            besluit=besluit, informatieobject=eio.canonical
        )
        besluit_url = reverse(besluit)
        eio_url = reverse(eio)
        # re-use the ZIO UUID for OIO
        bio_url = reverse("objectinformatieobject-detail", kwargs={"uuid": bio.uuid})

        response = self.client.post(
            self.list_url,
            {
                "object": f"http://testserver.nl{besluit_url}",
                "informatieobject": f"http://testserver{eio_url}",
                "objectType": "besluit",
            },
            HTTP_HOST="testserver.nl",
        )

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(
            response.data,
            {
                "url": f"http://testserver.nl{bio_url}",
                "object": f"http://testserver.nl{besluit_url}",
                "informatieobject": f"http://testserver.nl{eio_url}",
                "object_type": "besluit",
            },
        )
    def test_delete_document_fail_exising_relations_besluit(self):
        informatieobject = EnkelvoudigInformatieObjectCanonicalFactory.create()
        BesluitInformatieObjectFactory.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")
Ejemplo n.º 5
0
    def test_opvragen_informatieobjecten_besluit(self):
        besluit1, besluit2 = BesluitFactory.create_batch(2)

        besluit1_uri = reverse(besluit1)
        besluit2_uri = reverse(besluit2)

        BesluitInformatieObjectFactory.create_batch(3, besluit=besluit1)
        BesluitInformatieObjectFactory.create_batch(2, besluit=besluit2)

        base_uri = get_operation_url("besluitinformatieobject_list")

        url1 = f"{base_uri}?besluit={besluit1_uri}"
        response1 = self.client.get(url1)
        self.assertEqual(len(response1.data), 3)

        url2 = f"{base_uri}?besluit={besluit2_uri}"
        response2 = self.client.get(url2)
        self.assertEqual(len(response2.data), 2)
    def test_filter(self):
        bio = BesluitInformatieObjectFactory.create()
        besluit_url = reverse(bio.besluit)
        bio_list_url = reverse("besluitinformatieobject-list")

        response = self.client.get(
            bio_list_url, {"besluit": f"http://testserver{besluit_url}"})

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]["besluit"],
                         f"http://testserver{besluit_url}")
    def test_delete(self):
        bio = BesluitInformatieObjectFactory.create()
        bio_url = reverse(bio)

        response = self.client.delete(bio_url)

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

        # Relation is gone, besluit still exists.
        self.assertFalse(BesluitInformatieObject.objects.exists())
        self.assertTrue(Besluit.objects.exists())
Ejemplo n.º 8
0
    def test_cannot_read_without_correct_scope(self):
        besluit = BesluitFactory.create()
        bio = BesluitInformatieObjectFactory.create(besluit=besluit)
        urls = [
            reverse("besluit-list"),
            reverse(besluit),
            reverse("besluitinformatieobject-list"),
            reverse(bio),
        ]

        for url in urls:
            with self.subTest(url=url):
                self.assertForbidden(url, method="get")
Ejemplo n.º 9
0
    def test_list_bio_limited_to_authorized_zaken(self):
        besluit1 = BesluitFactory.create(besluittype=self.besluittype)
        besluit2 = BesluitFactory.create()

        url = reverse(BesluitInformatieObject)

        # must show up
        bio1 = BesluitInformatieObjectFactory.create(besluit=besluit1)
        # must not show up
        bio2 = BesluitInformatieObjectFactory.create(besluit=besluit2)

        response = self.client.get(url)

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

        response_data = response.json()

        self.assertEqual(len(response_data), 1)

        besluit_url = reverse(bio1.besluit)
        self.assertEqual(response_data[0]["besluit"],
                         f"http://testserver{besluit_url}")
    def test_read_besluit(self):
        bio = BesluitInformatieObjectFactory.create()
        bio_detail_url = reverse(bio)

        response = self.client.get(bio_detail_url)

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

        besluit_url = reverse(bio.besluit)
        io_url = reverse(bio.informatieobject.latest_version)
        expected = {
            "url": f"http://testserver{bio_detail_url}",
            "informatieobject": f"http://testserver{io_url}",
            "besluit": f"http://testserver{besluit_url}",
        }

        self.assertEqual(response.json(), expected)
    def test_duplicate_object(self):
        """
        Test the (informatieobject, object) unique together validation.
        """
        bio = BesluitInformatieObjectFactory.create()
        besluit_url = reverse(bio.besluit)
        io_url = reverse(bio.informatieobject.latest_version)

        content = {
            "informatieobject": f"http://testserver{io_url}",
            "besluit": f"http://testserver{besluit_url}",
        }

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

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

        error = get_validation_errors(response, "nonFieldErrors")
        self.assertEqual(error["code"], "unique")
    def test_update_besluit(self):
        bio = BesluitInformatieObjectFactory.create()
        bio_detail_url = reverse(bio)
        besluit = BesluitFactory.create()
        besluit_url = reverse(besluit)
        io = EnkelvoudigInformatieObjectFactory.create()
        io_url = reverse(io)

        response = self.client.patch(
            bio_detail_url,
            {
                "besluit": f"http://testserver{besluit_url}",
                "informatieobject": f"http://testserver{io_url}",
            },
        )

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

        for field in ["besluit", "informatieobject"]:
            with self.subTest(field=field):
                error = get_validation_errors(response, field)
                self.assertEqual(error["code"], IsImmutableValidator.code)