def test_list_zaakinformatieobject_limited_to_authorized_zaken(self):
        # must show up
        zio1 = ZaakInformatieObjectFactory.create(
            zaak__zaaktype='https://zaaktype.nl/ok',
            zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.
            openbaar,
            informatieobject=INFORMATIEOBJECT)
        # must not show up
        zio2 = ZaakInformatieObjectFactory.create(
            zaak__zaaktype='https://zaaktype.nl/not_ok',
            zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.
            openbaar,
            informatieobject=INFORMATIEOBJECT)
        # must not show up
        zio3 = ZaakInformatieObjectFactory.create(
            zaak__zaaktype='https://zaaktype.nl/ok',
            zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.
            vertrouwelijk,
            informatieobject=INFORMATIEOBJECT)

        url = reverse(ZaakInformatieObject)

        response = self.client.get(url)

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

        zaak_url = reverse(zio1.zaak)
        self.assertEqual(response.data[0]['zaak'],
                         f'http://testserver{zaak_url}')
Esempio n. 2
0
    def test_delete_zaak_cascades_properly(self):
        """
        Deleting a zaak causes all related objects to be deleted as well.
        """
        zaak = ZaakFactory.create(zaaktype=ZAAKTYPE)

        ZaakFactory.create(hoofdzaak=zaak, zaaktype=ZAAKTYPE)

        ZaakEigenschapFactory.create(zaak=zaak)
        StatusFactory.create(zaak=zaak)
        RolFactory.create(zaak=zaak)
        ResultaatFactory.create(zaak=zaak)
        ZaakObjectFactory.create(zaak=zaak)
        ZaakInformatieObjectFactory.create(zaak=zaak)
        KlantContactFactory.create(zaak=zaak)

        zaak_delete_url = get_operation_url('zaak_delete', uuid=zaak.uuid)

        response = self.client.delete(zaak_delete_url, **ZAAK_WRITE_KWARGS)
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT,
                         response.data)

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

        self.assertEqual(ZaakEigenschap.objects.all().count(), 0)
        self.assertEqual(Status.objects.all().count(), 0)
        self.assertEqual(Rol.objects.all().count(), 0)
        self.assertEqual(Resultaat.objects.all().count(), 0)
        self.assertEqual(ZaakObject.objects.all().count(), 0)
        self.assertEqual(ZaakInformatieObject.objects.all().count(), 0)
        self.assertEqual(KlantContact.objects.all().count(), 0)
    def test_update_zaak(self):
        zaak = ZaakFactory.create()
        zaak_url = reverse('zaak-detail',
                           kwargs={
                               'version': '1',
                               'uuid': zaak.uuid,
                           })

        zio = ZaakInformatieObjectFactory.create(
            informatieobject=INFORMATIEOBJECT)
        zio_detail_url = reverse('zaakinformatieobject-detail',
                                 kwargs={
                                     'version': '1',
                                     'uuid': zio.uuid,
                                 })

        response = self.client.patch(
            zio_detail_url, {
                'zaak': f'http://testserver{zaak_url}',
                'informatieobject': 'https://bla.com',
            })

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

        for field in ['zaak', 'informatieobject']:
            with self.subTest(field=field):
                error = get_validation_errors(response, field)
                self.assertEqual(error['code'], IsImmutableValidator.code)
    def test_read_zaak(self):
        zio = ZaakInformatieObjectFactory.create(
            informatieobject=INFORMATIEOBJECT)
        # Retrieve from the API

        zio_detail_url = reverse('zaakinformatieobject-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)

        zaak_url = reverse('zaak-detail',
                           kwargs={
                               'version': '1',
                               'uuid': zio.zaak.uuid,
                           })

        expected = {
            'url': f'http://testserver{zio_detail_url}',
            'informatieobject': zio.informatieobject,
            'zaak': f'http://testserver{zaak_url}',
            'aardRelatieWeergave':
            RelatieAarden.labels[RelatieAarden.hoort_bij],
            'titel': '',
            'beschrijving': '',
            'registratiedatum': '2018-09-20T12:00:00Z'
        }

        self.assertEqual(response.json(), expected)
    def test_cannot_set_archiefstatus_when_not_all_documents_are_gearchiveerd(
            self):
        zaak = ZaakFactory.create(
            archiefnominatie=Archiefnominatie.vernietigen,
            archiefactiedatum=date.today(),
            zaaktype=ZAAKTYPE)
        zio = ZaakInformatieObjectFactory.create(
            zaak=zaak,
            informatieobject=ENKELVOUDIGINFORMATIEOBJECT,
        )

        zaak_patch_url = get_operation_url('zaak_partial_update',
                                           uuid=zaak.uuid)

        data = {'archiefstatus': Archiefstatus.gearchiveerd}

        responses = {
            ENKELVOUDIGINFORMATIEOBJECT: {
                'url': ENKELVOUDIGINFORMATIEOBJECT,
                'status': 'in_bewerking',
            },
        }

        with mock_client(responses):
            response = self.client.patch(zaak_patch_url, data,
                                         **ZAAK_WRITE_KWARGS)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST,
                         response.data)
    def test_duplicate_object(self, *mocks):
        """
        Test the (informatieobject, object) unique together validation.
        """
        zio = ZaakInformatieObjectFactory.create(
            informatieobject=INFORMATIEOBJECT, zaak__zaaktype=ZAAKTYPE)
        zaak_url = reverse("zaak-detail",
                           kwargs={
                               "version": "1",
                               "uuid": zio.zaak.uuid
                           })

        content = {
            "informatieobject": zio.informatieobject,
            "zaak": f"http://testserver{zaak_url}",
        }

        # Send to the API
        with mock_client(RESPONSES):
            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")
Esempio n. 7
0
    def test_conditional_get_304(self):
        zio = ZaakInformatieObjectFactory.create(with_etag=True)

        response = self.client.get(reverse(zio),
                                   HTTP_IF_NONE_MATCH=f'"{zio._etag}"')

        self.assertEqual(response.status_code, status.HTTP_304_NOT_MODIFIED)
    def test_read_zaak(self):
        zio = ZaakInformatieObjectFactory.create(
            informatieobject=INFORMATIEOBJECT)
        # Retrieve from the API

        zio_detail_url = reverse("zaakinformatieobject-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)

        zaak_url = reverse("zaak-detail",
                           kwargs={
                               "version": "1",
                               "uuid": zio.zaak.uuid
                           })

        expected = {
            "url": f"http://testserver{zio_detail_url}",
            "uuid": str(zio.uuid),
            "informatieobject": zio.informatieobject,
            "zaak": f"http://testserver{zaak_url}",
            "aardRelatieWeergave":
            RelatieAarden.labels[RelatieAarden.hoort_bij],
            "titel": "",
            "beschrijving": "",
            "registratiedatum": "2018-09-20T12:00:00Z",
        }

        self.assertEqual(response.json(), expected)
    def test_update_zaak(self, *mocks):
        zaak = ZaakFactory.create()
        zaak_url = reverse("zaak-detail",
                           kwargs={
                               "version": "1",
                               "uuid": zaak.uuid
                           })

        zio = ZaakInformatieObjectFactory.create(
            informatieobject=INFORMATIEOBJECT)
        zio_detail_url = reverse("zaakinformatieobject-detail",
                                 kwargs={
                                     "version": "1",
                                     "uuid": zio.uuid
                                 })

        response = self.client.patch(
            zio_detail_url,
            {
                "zaak": f"http://testserver{zaak_url}",
                "informatieobject": "https://bla.com",
            },
        )

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

        for field in ["zaak", "informatieobject"]:
            with self.subTest(field=field):
                error = get_validation_errors(response, field)
                self.assertEqual(error["code"], IsImmutableValidator.code)
Esempio n. 10
0
    def test_delete(self):
        zio = ZaakInformatieObjectFactory.create()
        zaak = zio.zaak
        url = reverse('zaakinformatieobject-detail',
                      kwargs={
                          'zaak_uuid': zaak.uuid,
                          'uuid': zio.uuid
                      })

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        self.assertFalse(zaak.zaakinformatieobject_set.exists())
    def test_filter(self):
        zio = ZaakInformatieObjectFactory.create(
            informatieobject=INFORMATIEOBJECT)
        zaak_url = reverse('zaak-detail',
                           kwargs={
                               'version': '1',
                               'uuid': zio.zaak.uuid,
                           })
        zio_list_url = reverse('zaakinformatieobject-list',
                               kwargs={'version': '1'})

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

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['zaak'],
                         f'http://testserver{zaak_url}')
    def test_delete(self):
        zio = ZaakInformatieObjectFactory.create(
            informatieobject=INFORMATIEOBJECT)
        zio_url = reverse("zaakinformatieobject-detail",
                          kwargs={
                              "version": "1",
                              "uuid": zio.uuid
                          })

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

        response = self.client.delete(zio_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, zaak still exists.
        self.assertFalse(ZaakInformatieObject.objects.exists())
        self.assertTrue(Zaak.objects.exists())
    def test_filter(self):
        zio = ZaakInformatieObjectFactory.create(
            informatieobject=INFORMATIEOBJECT)
        zaak_url = reverse("zaak-detail",
                           kwargs={
                               "version": "1",
                               "uuid": zio.zaak.uuid
                           })
        zio_list_url = reverse("zaakinformatieobject-list",
                               kwargs={"version": "1"})

        response = self.client.get(
            zio_list_url,
            {"zaak": f"http://testserver.com{zaak_url}"},
            HTTP_HOST="testserver.com",
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]["zaak"],
                         f"http://testserver.com{zaak_url}")
    def test_duplicate_object(self):
        """
        Test the (informatieobject, object) unique together validation.
        """
        zio = ZaakInformatieObjectFactory.create(
            informatieobject=INFORMATIEOBJECT)
        zaak_url = reverse('zaak-detail',
                           kwargs={
                               'version': '1',
                               'uuid': zio.zaak.uuid,
                           })

        content = {
            'informatieobject': zio.informatieobject,
            'zaak': f'http://testserver{zaak_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')
Esempio n. 15
0
    def test_zaakinformatieobject_get_cache_header(self):
        zaakinformatieobject = ZaakInformatieObjectFactory.create()

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

        self.assertHasETag(response)
Esempio n. 16
0
    def test_zaakinformatieobject_head_cache_header(self):
        zaakinformatieobject = ZaakInformatieObjectFactory.create()

        self.assertHeadHasETag(reverse(zaakinformatieobject))
Esempio n. 17
0
    def test_conditional_get_stale(self):
        zio = ZaakInformatieObjectFactory.create(with_etag=True)

        response = self.client.get(reverse(zio), HTTP_IF_NONE_MATCH='"old"')

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