Esempio n. 1
0
    def test_relevante_andere_zaken_valid_zaak_resource(self, *mocks):
        url = reverse("zaak-list")

        zaak_body = {
            "zaaktype": ZAAKTYPE,
            "bronorganisatie": "517439943",
            "verantwoordelijkeOrganisatie": "517439943",
            "registratiedatum": "2018-06-11",
            "startdatum": "2018-06-11",
            "vertrouwelijkheidaanduiding": VertrouwelijkheidsAanduiding.openbaar,
        }

        with mock_client(RESPONSES):
            response = self.client.post(
                url, zaak_body, HTTP_HOST=self.valid_testserver_url, **ZAAK_WRITE_KWARGS
            )

        andere_zaak_url = response.data["url"]

        zaak_body.update(
            {
                "relevanteAndereZaken": [
                    {"url": andere_zaak_url, "aardRelatie": AardZaakRelatie.vervolg}
                ]
            }
        )

        with mock_client(RESPONSES):
            response = self.client.post(
                url, zaak_body, HTTP_HOST=self.valid_testserver_url, **ZAAK_WRITE_KWARGS
            )

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Esempio n. 2
0
    def test_relevante_andere_zaken_valid_zaak_url(self):
        url = reverse('zaak-list')

        zaak_body = {
            'zaaktype': ZAAKTYPE,
            'bronorganisatie': '517439943',
            'verantwoordelijkeOrganisatie': '517439943',
            'registratiedatum': '2018-06-11',
            'startdatum': '2018-06-11',
            'vertrouwelijkheidaanduiding':
            VertrouwelijkheidsAanduiding.openbaar,
        }

        with mock_client(RESPONSES):
            response = self.client.post(url,
                                        zaak_body,
                                        HTTP_HOST=self.valid_testserver_url,
                                        **ZAAK_WRITE_KWARGS)

        andere_zaak_url = response.data['url']

        zaak_body.update({'relevanteAndereZaken': [andere_zaak_url]})

        with mock_client(RESPONSES):
            response = self.client.post(url,
                                        zaak_body,
                                        HTTP_HOST=self.valid_testserver_url,
                                        **ZAAK_WRITE_KWARGS)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Esempio n. 3
0
    def test_statustype_zaaktype_mismatch(self, *mocks):
        responses = {
            STATUSTYPE: {
                "url": STATUSTYPE,
                "zaaktype": "http://example.com/zaaktypen/1234",
                "volgnummer": 1,
                "isEindstatus": False,
            }
        }

        zaak = ZaakFactory.create(zaaktype=ZAAKTYPE)
        zaak_url = reverse("zaak-detail", kwargs={"uuid": zaak.uuid})

        list_url = reverse("status-list")

        with mock_client(responses):
            response = self.client.post(
                list_url,
                {
                    "zaak": zaak_url,
                    "statustype": STATUSTYPE,
                    "datumStatusGezet": isodatetime(2018, 10, 1, 10, 00, 00),
                },
            )

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

        error = get_validation_errors(response, "nonFieldErrors")
        self.assertEqual(error["code"], "zaaktype-mismatch")
Esempio n. 4
0
    def test_create_status_existing_combination_zaak_datum_status_gezet(self, *mocks):
        zaak = ZaakFactory.create()
        status = StatusFactory.create(
            zaak=zaak, datum_status_gezet="2019-01-01T12:00:00Z"
        )

        list_url = reverse("status-list")

        STATUSTYPE = "https://www.ztc.nl/statustypen/1234"
        responses = {
            STATUSTYPE: {
                "url": STATUSTYPE,
                "zaaktype": zaak.zaaktype,
                "volgnummer": 1,
                "isEindstatus": False,
            }
        }

        data = {
            "zaak": reverse(zaak),
            "statustype": STATUSTYPE,
            "datumStatusGezet": "2019-01-01T12:00:00Z",
        }

        with mock_client(responses):
            response = self.client.post(list_url, data)

        error = get_validation_errors(response, "nonFieldErrors")
        self.assertEqual(error["code"], "unique")
    def test_invalide_product_of_dienst(self):
        url = reverse('zaak-list')

        responses = {
            'https://example.com/zaaktype/123': {
                'url': 'https://example.com/zaaktype/123',
                'productenOfDiensten': [
                    'https://example.com/product/123',
                ]
            }
        }

        with mock_client(responses):
            response = self.client.post(
                url, {
                    'zaaktype': 'https://example.com/zaaktype/123',
                    'vertrouwelijkheidaanduiding':
                    VertrouwelijkheidsAanduiding.openbaar,
                    'bronorganisatie': '517439943',
                    'verantwoordelijkeOrganisatie': '517439943',
                    'registratiedatum': '2018-12-24',
                    'startdatum': '2018-12-24',
                    'productenOfDiensten': ['https://example.com/product/999'],
                }, **ZAAK_WRITE_KWARGS)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        validation_error = get_validation_errors(response,
                                                 'productenOfDiensten')
        self.assertEqual(validation_error['code'], 'invalid-products-services')
    def test_sync_create_fails(self):
        self.mocked_sync_create.side_effect = SyncError("Sync failed")

        zaak = ZaakFactory.create(zaaktype=ZAAKTYPE)
        zaak_url = reverse("zaak-detail",
                           kwargs={
                               "version": "1",
                               "uuid": zaak.uuid
                           })

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

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

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

        # transaction must be rolled back
        self.assertFalse(ZaakInformatieObject.objects.exists())
Esempio n. 7
0
    def test_reopen_zaak_allowed(self, *mocks):
        zaak = ZaakFactory.create(
            einddatum=timezone.now().date(),
            archiefactiedatum="2020-01-01",
            archiefnominatie=Archiefnominatie.blijvend_bewaren,
            zaaktype=ZAAKTYPE,
        )
        status_create_url = get_operation_url("status_create")
        self.autorisatie.scopes = [SCOPEN_ZAKEN_HEROPENEN]
        self.autorisatie.save()

        data = {
            "zaak": reverse(zaak),
            "statustype": STATUS_TYPE,
            "datumStatusGezet": datetime.datetime.now().isoformat(),
        }
        with mock_client(RESPONSES):
            response = self.client.post(status_create_url, data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED,
                         response.data)

        zaak.refresh_from_db()
        self.assertIsNone(zaak.einddatum)
        self.assertIsNone(zaak.archiefactiedatum)
        self.assertIsNone(zaak.archiefnominatie)
Esempio n. 8
0
    def test_create_zaakeigenschap_not_in_zaaktypen_fails(self, *mocks):
        zaak = ZaakFactory.create(zaaktype=ZAAKTYPE)

        responses = {
            EIGENSCHAP_OBJECTTYPE: {
                "url": EIGENSCHAP_OBJECTTYPE,
                "naam": "foobar",
                "zaaktype": "https://example.com/ztc/api/v1/zaaktypen/2",
            },
            ZAAKTYPE: {
                "url": ZAAKTYPE,
                "eigenschappen": [EIGENSCHAP_NAAM_BOOT]
            },
        }

        url = get_operation_url("zaakeigenschap_create", zaak_uuid=zaak.uuid)
        zaak_url = get_operation_url("zaak_read", uuid=zaak.uuid)
        data = {
            "zaak": zaak_url,
            "eigenschap": EIGENSCHAP_OBJECTTYPE,
            "waarde": "overlast_water",
        }

        with mock_client(responses):
            response = self.client.post(url, data)

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

        error = get_validation_errors(response, "nonFieldErrors")
        self.assertEqual(error["code"], "zaaktype-mismatch")
Esempio n. 9
0
    def test_update_zaak_audittrails(self, *mocks):
        zaak_data = self._create_zaak()

        modified_data = deepcopy(zaak_data)
        url = modified_data.pop("url")
        modified_data.pop("verlenging")
        modified_data["toelichting"] = "aangepast"

        with mock_client(self.responses):
            response = self.client.put(url, modified_data, **ZAAK_WRITE_KWARGS)
            zaak_response = response.data

        audittrails = AuditTrail.objects.filter(
            hoofd_object=zaak_response["url"]
        ).order_by("pk")
        self.assertEqual(audittrails.count(), 2)

        # Verify that the audittrail for the Zaak update contains the correct
        # information
        zaak_update_audittrail = audittrails[1]
        self.assertEqual(zaak_update_audittrail.bron, "ZRC")
        self.assertEqual(zaak_update_audittrail.actie, "update")
        self.assertEqual(zaak_update_audittrail.resultaat, 200)
        self.assertEqual(zaak_update_audittrail.oud, zaak_data)
        self.assertEqual(zaak_update_audittrail.nieuw, zaak_response)
Esempio n. 10
0
    def test_create_zaakinformatieobject_audittrail(self, *mocks):
        zaak_data = self._create_zaak()

        url = reverse(ZaakInformatieObject)

        with mock_client(self.responses):
            response = self.client.post(
                url, {"zaak": zaak_data["url"], "informatieobject": INFORMATIEOBJECT}
            )

        zaakinformatieobject_response = response.data

        audittrails = AuditTrail.objects.filter(hoofd_object=zaak_data["url"]).order_by(
            "pk"
        )
        self.assertEqual(audittrails.count(), 2)

        # Verify that the audittrail for the ZaakInformatieObject creation
        # contains the correct information
        zio_create_audittrail = audittrails[1]
        self.assertEqual(zio_create_audittrail.bron, "ZRC")
        self.assertEqual(zio_create_audittrail.actie, "create")
        self.assertEqual(zio_create_audittrail.resultaat, 201)
        self.assertEqual(zio_create_audittrail.oud, None)
        self.assertEqual(zio_create_audittrail.nieuw, zaakinformatieobject_response)
    def test_create_objectcontactmoment(self, *mocks):
        contactmoment = ContactMomentFactory.create()
        contactmoment_url = reverse(contactmoment)
        list_url = reverse(ObjectContactMoment)
        data = {
            "contactmoment": contactmoment_url,
            "objectType": ObjectTypes.zaak,
            "object": ZAAK,
        }
        responses = {
            "http://example.com/api/v1/zaakcontactmomenten": [{
                "url":
                f"https://example.com/api/v1/zaakcontactmomenten/{uuid.uuid4()}",
                "contactmoment":
                f"http://testserver/api/v1/contactmomenten/{uuid.uuid4()}",
                "zaak": ZAAK,
            }]
        }
        with mock_client(responses):
            response = self.client.post(list_url, data)

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

        objectcontactmoment = ObjectContactMoment.objects.get()

        self.assertEqual(objectcontactmoment.contactmoment, contactmoment)
        self.assertEqual(objectcontactmoment.object_type, ObjectTypes.zaak)
        self.assertEqual(objectcontactmoment.object, ZAAK)
Esempio n. 12
0
    def test_zaak_vertrouwelijkheidaanduiding_afgeleid(self):
        """
        Assert that the default vertrouwelijkheidaanduiding is set.
        """
        url = reverse('zaak-list')
        responses = {
            ZAAKTYPE: {
                'url':
                ZAAKTYPE,
                'vertrouwelijkheidaanduiding':
                VertrouwelijkheidsAanduiding.zaakvertrouwelijk,
            }
        }

        with mock_client(responses):
            response = self.client.post(
                url, {
                    'zaaktype': ZAAKTYPE,
                    'bronorganisatie': '517439943',
                    'verantwoordelijkeOrganisatie': '517439943',
                    'registratiedatum': '2018-12-24',
                    'startdatum': '2018-12-24',
                }, **ZAAK_WRITE_KWARGS)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(
            response.data['vertrouwelijkheidaanduiding'],
            VertrouwelijkheidsAanduiding.zaakvertrouwelijk,
        )
    def test_add_resultaat_on_zaak_with_incorrect_eigenschap_fails(self):
        """
        Attempt to add RESULTAAT with incorrect ZTC-configuration.
        """
        zaak = ZaakFactory.create()
        zaak_url = get_operation_url('zaak_read', uuid=zaak.uuid)

        resultaat_create_url = get_operation_url('resultaat_create')
        data = {
            'zaak': zaak_url,
            'resultaatType': RESULTAATTYPE,
            'toelichting': '',
        }

        responses = {
            RESULTAATTYPE: {
                'url': RESULTAATTYPE,
                'archiefactietermijn': 'P10Y',
                'archiefnominatie': Archiefnominatie.blijvend_bewaren,
                # ZTC indicates there is a EIGENSCHAP called "brondatum", but there isn't one.
                'brondatumArchiefprocedure': {
                    'afleidingswijze':
                    BrondatumArchiefprocedureAfleidingswijze.eigenschap,
                    'datumkenmerk': 'brondatum',
                    'objecttype': None,
                    'procestermijn': None,
                }
            }
        }

        with mock_client(responses):
            response = self.client.post(resultaat_create_url, data)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST,
                         response.data)
Esempio n. 14
0
    def test_create_eigenschap(self, *mocks):
        zaak = ZaakFactory.create(zaaktype=ZAAKTYPE)
        zaak_url = reverse(zaak)

        list_url = reverse("zaakeigenschap-list", kwargs={"zaak_uuid": zaak.uuid})

        responses = {
            "http://ztc.com/eigenschappen/1234": {
                "url": "http://ztc.com/eigenschappen/1234",
                "naam": "test",
                "zaaktype": ZAAKTYPE,
            },
            ZAAKTYPE: {
                "url": ZAAKTYPE,
                "eigenschappen": ["http://ztc.com/eigenschappen/1234"],
            },
        }

        with mock_client(responses):
            response = self.client.post(
                list_url,
                {
                    "zaak": zaak_url,
                    "eigenschap": "http://ztc.com/eigenschappen/1234",
                    "waarde": "test",
                },
            )

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Esempio n. 15
0
    def test_zet_zaakstatus(self, *mocks):
        """
        De actuele status van een zaak moet gezet worden bij het aanmaken
        van de zaak.
        """
        url = get_operation_url("status_create")
        zaak = ZaakFactory.create(zaaktype=ZAAKTYPE)
        zaak_url = get_operation_url("zaak_read", uuid=zaak.uuid)
        data = {
            "zaak": zaak_url,
            "statustype": STATUS_TYPE,
            "datumStatusGezet": isodatetime(2018, 6, 6, 17, 23, 43),
        }

        with mock_client(STATUSTYPE_RESPONSE):
            response = self.client.post(url, data)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED,
                         response.data)
        response_data = response.json()
        status_ = Status.objects.get()
        self.assertEqual(status_.zaak, zaak)
        detail_url = get_operation_url("status_read", uuid=status_.uuid)
        self.assertEqual(
            response_data,
            {
                "url": f"http://testserver{detail_url}",
                "uuid": str(status_.uuid),
                "zaak": f"http://testserver{zaak_url}",
                "statustype": STATUS_TYPE,
                "datumStatusGezet": "2018-06-06T17:23:43Z",  # UTC
                "statustoelichting": "",
            },
        )
Esempio n. 16
0
    def test_validate_selectielijstklasse_invalid_resource(self):
        url = reverse("zaak-list")
        responses = {
            "https://ztc.com/resultaten/1234": {
                "some": "incorrect property"
            }
        }

        with mock_client(responses):
            response = self.client.post(
                url,
                {
                    "selectielijstklasse": "https://ztc.com/resultaten/1234",
                    "zaaktype": f"http://testserver{self.zaaktype_url}",
                    "bronorganisatie": "517439943",
                    "verantwoordelijkeOrganisatie": "517439943",
                    "registratiedatum": "2018-06-11",
                    "startdatum": "2018-06-11",
                },
                **ZAAK_WRITE_KWARGS,
            )

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

        validation_error = get_validation_errors(response,
                                                 "selectielijstklasse")
        self.assertEqual(validation_error["code"], "invalid-resource")
    def registreer_domein_data(self):
        zaak_uuid = self.references['zaak_url'].rsplit('/')[-1]
        url = get_operation_url('zaakeigenschap_create', zaak_uuid=zaak_uuid)

        responses = {
            EIGENSCHAP_OBJECTTYPE: {
                'url': EIGENSCHAP_OBJECTTYPE,
                'naam': 'melding_type',
            },
            EIGENSCHAP_NAAM_BOOT: {
                'url': EIGENSCHAP_NAAM_BOOT,
                'naam': 'waternet_naam_boot',
            }
        }

        with mock_client(responses):
            self.client.post(
                url, {
                    'zaak': self.references['zaak_url'],
                    'eigenschap': EIGENSCHAP_OBJECTTYPE,
                    'waarde': 'overlast_water',
                })
            self.client.post(
                url, {
                    'zaak': self.references['zaak_url'],
                    'eigenschap': EIGENSCHAP_NAAM_BOOT,
                    'waarde': TEST_DATA['waternet_naam_boot'],
                })
    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)
Esempio n. 19
0
    def test_meerdere_coordinatoren_verboden(self, *mocks):
        """
        Uit RGBZ 2.0, deel 2, Attribuutsoort Rolomschrijving (bij relatieklasse
        ROL):

        Bij een ZAAK kan maximaal één ROL met als Rolomschrijving generiek
        'Initiator' voor komen.
        """
        zaak = ZaakFactory.create(zaaktype=ZAAKTYPE)
        RolFactory.create(
            zaak=zaak,
            betrokkene_type=RolTypes.natuurlijk_persoon,
            omschrijving=RolOmschrijving.zaakcoordinator,
            omschrijving_generiek=RolOmschrijving.zaakcoordinator,
        )
        zaak_url = get_operation_url("zaak_read", uuid=zaak.uuid)
        url = get_operation_url("rol_create")

        with requests_mock.Mocker() as m:
            m.get(ROLTYPE3, json=ROLTYPE3_RESPONSE)
            with mock_client({ROLTYPE3: ROLTYPE3_RESPONSE}):
                response = self.client.post(
                    url,
                    {
                        "zaak": zaak_url,
                        "betrokkene": WATERNET,
                        "betrokkeneType": RolTypes.organisatorische_eenheid,
                        "roltype": ROLTYPE3,
                        "roltoelichting": "Melder",
                    },
                )

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Esempio n. 20
0
    def test_add_resultaat_on_zaak_with_remote_zaakobjecten_causes_archiefactiedatum_to_be_set(
        self, ):
        """
        Add RESULTAAT that causes `archiefactiedatum` to be set.
        """
        zaak = ZaakFactory.create()
        zaak_url = get_operation_url("zaak_read", uuid=zaak.uuid)
        zaak_object1 = ZaakObjectFactory.create(zaak=zaak)
        zaak_object2 = ZaakObjectFactory.create(
            zaak=zaak, object_type=zaak_object1.object_type)
        resultaattype = ResultaatTypeFactory.create(
            archiefactietermijn="P10Y",
            archiefnominatie=Archiefnominatie.blijvend_bewaren,
            brondatum_archiefprocedure_afleidingswijze=
            BrondatumArchiefprocedureAfleidingswijze.zaakobject,
            brondatum_archiefprocedure_datumkenmerk="einddatum",
            brondatum_archiefprocedure_objecttype=zaak_object1.object_type,
            zaaktype=zaak.zaaktype,
        )
        resultaattype_url = reverse(resultaattype)
        responses = {
            zaak_object1.object: {
                "einddatum": isodatetime(2019, 1, 1)
            },
            zaak_object2.object: {
                "einddatum": isodatetime(2022, 1, 1)
            },
        }

        # add resultaat
        resultaat_create_url = get_operation_url("resultaat_create")
        data = {
            "zaak": zaak_url,
            "resultaattype": f"http://testserver{resultaattype_url}",
            "toelichting": "",
        }

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

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

        # add final status to the case to close it and to calculate archive parameters
        status_create_url = get_operation_url("status_create")
        statustype = StatusTypeFactory.create(zaaktype=zaak.zaaktype)
        statustype_url = reverse(statustype)
        data = {
            "zaak": zaak_url,
            "statustype": f"http://testserver{statustype_url}",
            "datumStatusGezet": "2018-10-18T20:00:00Z",
        }

        with mock_client(responses):
            response = self.client.post(status_create_url, data)

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

        zaak.refresh_from_db()
        self.assertEqual(zaak.archiefactiedatum, date(2032, 1, 1))
    def test_create_objectverzoek(self, *mocks):
        verzoek = VerzoekFactory.create()
        verzoek_url = reverse(verzoek)
        list_url = reverse(ObjectVerzoek)
        data = {
            "verzoek": verzoek_url,
            "objectType": ObjectTypes.zaak,
            "object": ZAAK,
        }
        responses = {
            "http://example.com/api/v1/zaakverzoeken": [{
                "url":
                f"https://example.com/api/v1/zaakverzoeken/{uuid.uuid4()}",
                "verzoek":
                f"http://testserver/api/v1/verzoeken/{uuid.uuid4()}",
                "zaak": ZAAK,
            }]
        }
        with mock_client(responses):
            response = self.client.post(list_url, data)

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

        objectverzoek = ObjectVerzoek.objects.get()

        self.assertEqual(objectverzoek.verzoek, verzoek)
        self.assertEqual(objectverzoek.object_type, ObjectTypes.zaak)
        self.assertEqual(objectverzoek.object, ZAAK)
    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. 23
0
    def test_zaak_met_producten(self):
        url = reverse('zaak-list')
        token = generate_jwt(scopes=self.scopes + [SCOPE_ZAKEN_BIJWERKEN],
                             zaaktypes=['https://example.com/zaaktype/123'])
        self.client.credentials(HTTP_AUTHORIZATION=token)

        responses = {
            'https://example.com/zaaktype/123': {
                'url':
                'https://example.com/zaaktype/123',
                'productenOfDiensten': [
                    'https://example.com/product/123',
                    'https://example.com/dienst/123',
                ]
            }
        }

        with mock_client(responses):
            response = self.client.post(
                url, {
                    'zaaktype': 'https://example.com/zaaktype/123',
                    'vertrouwelijkheidaanduiding':
                    VertrouwelijkheidsAanduiding.openbaar,
                    'bronorganisatie': '517439943',
                    'verantwoordelijkeOrganisatie': '517439943',
                    'registratiedatum': '2018-12-24',
                    'startdatum': '2018-12-24',
                    'productenOfDiensten': ['https://example.com/product/123'],
                }, **ZAAK_WRITE_KWARGS)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        zaak = Zaak.objects.get()
        self.assertEqual(len(zaak.producten_of_diensten), 1)

        # update
        with mock_client(responses):
            response2 = self.client.patch(
                response.data['url'], {
                    'productenOfDiensten': [
                        'https://example.com/product/123',
                        'https://example.com/dienst/123',
                    ]
                }, **ZAAK_WRITE_KWARGS)

        self.assertEqual(response2.status_code, status.HTTP_200_OK)
        zaak.refresh_from_db()
        self.assertEqual(len(zaak.producten_of_diensten), 2)
    def test_add_resultaat_on_zaak_with_hoofdzaak_causes_archiefactiedatum_to_be_set(
            self):
        """
        Add RESULTAAT that causes `archiefactiedatum` to be set.
        """
        hoofd_zaak = ZaakFactory.create(einddatum=date(2019, 1, 1),
                                        zaaktype=ZAAKTYPE)

        zaak = ZaakFactory.create(hoofdzaak=hoofd_zaak, zaaktype=ZAAKTYPE)
        zaak_url = get_operation_url('zaak_read', uuid=zaak.uuid)

        # add resultaat
        resultaat_create_url = get_operation_url('resultaat_create')
        data = {
            'zaak': zaak_url,
            'resultaatType': RESULTAATTYPE,
            'toelichting': '',
        }

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

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

        # add final status to the case to close it and to calculate archive parameters
        status_create_url = get_operation_url('status_create')
        responses = {
            RESULTAATTYPE: {
                'url': RESULTAATTYPE,
                'archiefactietermijn': 'P10Y',
                'archiefnominatie': Archiefnominatie.blijvend_bewaren,
                'brondatumArchiefprocedure': {
                    'afleidingswijze':
                    BrondatumArchiefprocedureAfleidingswijze.hoofdzaak,
                    'datumkenmerk': None,
                    'objecttype': None,
                    'procestermijn': None,
                }
            },
            STATUSTYPE: {
                'url': STATUSTYPE,
                'volgnummer': 2,
                'isEindstatus': True,
            }
        }
        data = {
            'zaak': zaak_url,
            'statusType': STATUSTYPE,
            'datumStatusGezet': '2018-10-18T20:00:00Z',
        }

        with mock_client(responses):
            response = self.client.post(status_create_url, data)

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

        zaak.refresh_from_db()
        self.assertEqual(zaak.archiefactiedatum, date(2029, 1, 1))
    def test_add_resultaat_on_zaak_with_ander_datumkenmerk_causes_archiefactiedatum_to_remain_empty(
            self):
        """
        Add RESULTAAT that causes `archiefactiedatum` to remain empty. It needs to be manually set based on the
        information in the RESULTAATTYPE.
        """
        zaak = ZaakFactory.create(zaaktype=ZAAKTYPE)
        zaak_url = get_operation_url('zaak_read', uuid=zaak.uuid)

        # add resultaat
        resultaat_create_url = get_operation_url('resultaat_create')
        data = {
            'zaak': zaak_url,
            'resultaatType': RESULTAATTYPE,
            'toelichting': '',
        }

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

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

        # add final status to the case to close it and to calculate archive parameters
        status_create_url = get_operation_url('status_create')
        responses = {
            RESULTAATTYPE: {
                'url': RESULTAATTYPE,
                'archiefactietermijn': 'P10Y',
                'archiefnominatie': Archiefnominatie.blijvend_bewaren,
                'brondatumArchiefprocedure': {
                    'afleidingswijze':
                    BrondatumArchiefprocedureAfleidingswijze.
                    ander_datumkenmerk,
                    'datumkenmerk': 'einddatum',
                    'registratie': 'LichtgevendeObjectenRegistratie',
                    'objecttype': 'Lantaarnpaal',
                    'procestermijn': None,
                }
            },
            STATUSTYPE: {
                'url': STATUSTYPE,
                'volgnummer': 2,
                'isEindstatus': True,
            }
        }
        data = {
            'zaak': zaak_url,
            'statusType': STATUSTYPE,
            'datumStatusGezet': '2018-10-18T20:00:00Z',
        }

        with mock_client(responses):
            response = self.client.post(status_create_url, data)

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

        zaak.refresh_from_db()
        self.assertIsNone(zaak.archiefactiedatum)
Esempio n. 26
0
    def test_handle_update_auth(self):
        applicatie = Applicatie.objects.create(client_ids=["id1"],
                                               label="before",
                                               heeft_alle_autorisaties=True)
        uuid = applicatie.uuid
        config = AuthorizationsConfig.get_solo()
        applicatie_url = f"{config.api_root}/applicaties/{uuid}"

        self.assertEqual(applicatie.autorisaties.count(), 0)

        # webhook_url = get_operation_url('notification_receive')
        webhook_url = reverse(
            "notificaties-webhook",
            kwargs={"version": settings.REST_FRAMEWORK["DEFAULT_VERSION"]},
        )
        responses = {
            applicatie_url: {
                "client_ids": ["id1"],
                "label":
                "after",
                "heeftAlleAutorisaties":
                False,
                "autorisaties": [{
                    "component":
                    "zrc",
                    "scopes": [
                        "zds.scopes.zaken.lezen",
                        "zds.scopes.zaken.aanmaken",
                    ],
                    "zaaktype":
                    "https://ref.tst.vng.cloud/zrc/api/v1/catalogus/1/zaaktypen/1",
                    "maxVertrouwelijkheidaanduiding":
                    VertrouwelijkheidsAanduiding.beperkt_openbaar,
                }],
            }
        }
        data = {
            "kanaal": "autorisaties",
            "hoofdObject": applicatie_url,
            "resource": "applicatie",
            "resourceUrl": applicatie_url,
            "actie": "partial_update",
            "aanmaakdatum": "2012-01-14T00:00:00Z",
            "kenmerken": {},
        }

        with mock_client(responses):
            response = self.client.post(webhook_url, data)

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

        applicatie.refresh_from_db()

        self.assertEqual(applicatie.uuid, uuid)
        self.assertEqual(applicatie.heeft_alle_autorisaties, False)
        self.assertEqual(applicatie.label, "after")
        self.assertEqual(applicatie.autorisaties.count(), 1)
    def test_handle_update_auth(self):
        applicatie = Applicatie.objects.create(client_ids=['id1'],
                                               label='before',
                                               heeft_alle_autorisaties=True)
        uuid = applicatie.uuid
        config = AuthorizationsConfig.get_solo()
        applicatie_url = f'{config.api_root}/applicaties/{uuid}'

        self.assertEqual(applicatie.autorisaties.count(), 0)

        # webhook_url = get_operation_url('notification_receive')
        webhook_url = reverse(
            'notificaties-webhook',
            kwargs={'version': settings.REST_FRAMEWORK['DEFAULT_VERSION']})
        responses = {
            applicatie_url: {
                'client_ids': ['id1'],
                'label':
                'after',
                'heeftAlleAutorisaties':
                False,
                'autorisaties': [{
                    'component':
                    'NRC',
                    'scopes': [
                        'zds.scopes.zaken.lezen',
                        'zds.scopes.zaken.aanmaken',
                    ],
                    'zaaktype':
                    'https://ref.tst.vng.cloud/zrc/api/v1/catalogus/1/zaaktypen/1',
                    'maxVertrouwelijkheidaanduiding':
                    VertrouwelijkheidsAanduiding.beperkt_openbaar,
                }],
            }
        }
        data = {
            'kanaal': 'autorisaties',
            'hoofdObject': applicatie_url,
            'resource': 'applicatie',
            'resourceUrl': applicatie_url,
            'actie': 'partial_update',
            'aanmaakdatum': '2012-01-14T00:00:00Z',
            'kenmerken': {}
        }

        with mock_client(responses):
            response = self.client.post(webhook_url, data)

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

        applicatie.refresh_from_db()

        self.assertEqual(applicatie.uuid, uuid)
        self.assertEqual(applicatie.heeft_alle_autorisaties, False)
        self.assertEqual(applicatie.label, 'after')
        self.assertEqual(applicatie.autorisaties.count(), 1)
    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)
Esempio n. 29
0
    def test_relevante_andere_zaken_invalid_resource(self, *mocks):
        url = reverse("zaak-list")

        zaak_body = {
            "zaaktype": ZAAKTYPE,
            "bronorganisatie": "517439943",
            "verantwoordelijkeOrganisatie": "517439943",
            "registratiedatum": "2018-06-11",
            "startdatum": "2018-06-11",
            "vertrouwelijkheidaanduiding": VertrouwelijkheidsAanduiding.openbaar,
        }

        with mock_client(RESPONSES):
            with patch("vng_api_common.validators.obj_has_shape", return_value=True):
                response = self.client.post(
                    url,
                    zaak_body,
                    HTTP_HOST=self.valid_testserver_url,
                    **ZAAK_WRITE_KWARGS,
                )

        andere_zaak_url = response.data["url"]

        zaak_body.update(
            {
                "relevanteAndereZaken": [
                    {"url": andere_zaak_url, "aardRelatie": AardZaakRelatie.vervolg}
                ]
            }
        )

        with mock_client(RESPONSES):
            with patch("vng_api_common.validators.obj_has_shape", return_value=False):
                response = self.client.post(
                    url,
                    zaak_body,
                    HTTP_HOST=self.valid_testserver_url,
                    **ZAAK_WRITE_KWARGS,
                )

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

        validation_error = get_validation_errors(response, "relevanteAndereZaken.0.url")
        self.assertEqual(validation_error["code"], "invalid-resource")
    def test_destroy_objectverzoek(self, *mocks):
        objectverzoek = ObjectVerzoekFactory.create(
            object=ZAAK, object_type=ObjectTypes.zaak)
        detail_url = reverse(objectverzoek)
        responses = {"http://example.com/api/v1/zaakverzoeken": []}

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

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