def test_update_document_no_url_mapping(self): iot1 = InformatieObjectTypeFactory.create(concept=False) iot2 = InformatieObjectTypeFactory.create(concept=False) eio = EnkelvoudigInformatieObjectFactory.create( informatieobjecttype=iot1) eio_url = reverse(eio) eio_response = self.client.get(eio_url) eio_data = eio_response.data lock_response = self.client.post(f"{eio_url}/lock") self.assertEqual(lock_response.status_code, status.HTTP_200_OK) lock = lock_response.data["lock"] eio_data.update({ "informatieobjecttype": f"http://testserver{reverse(iot2)}", "lock": lock, }) del eio_data["integriteit"] del eio_data["ondertekening"] # Remove all available mappings UrlMapping.objects.all().delete() response = self.client.put(eio_url, eio_data) self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) self.assertEqual( "CMIS-adapter could not shrink one of the URL fields.", response.data["detail"], )
def test_notification_body_current_and_future(self, m): mock_nrc_oas_get(m) m.post( "https://notificaties-api.vng.cloud/api/v1/notificaties", status_code=201 ) applicatie = ApplicatieFactory.create() AutorisatieSpecFactory.create( applicatie=applicatie, component=ComponentTypes.drc, scopes=["documenten.lezen"], max_vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.zeer_geheim, ) InformatieObjectTypeFactory.create() self.assertTrue(m.called) body = m.last_request.json() del body["aanmaakdatum"] path = reverse( "applicatie-detail", kwargs={"version": 1, "uuid": applicatie.uuid} ) expected = { "kanaal": "autorisaties", "hoofdObject": f"https://testserver{path}", "resource": "applicatie", "resourceUrl": f"https://testserver{path}", "actie": "update", "kenmerken": {}, } self.assertEqual(body, expected)
def test_add_autorisatie_all_current_and_future_informatieobjecttypen( self): data = { # management form "form-TOTAL_FORMS": 1, "form-INITIAL_FORMS": 0, "form-MIN_NUM_FORMS": 0, "form-MAX_NUM_FORMS": 1000, "form-0-component": ComponentTypes.drc, "form-0-scopes": ["documenten.lezen"], "form-0-related_type_selection": RelatedTypeSelectionMethods.all_current_and_future, "form-0-vertrouwelijkheidaanduiding": VertrouwelijkheidsAanduiding.beperkt_openbaar, } response = self.client.post(self.url, data) self.assertEqual(response.status_code, 302) self.assertFalse(Autorisatie.objects.exists()) # create a informatieobjecttype - this should trigger a new autorisatie being installed InformatieObjectTypeFactory.create() self.assertEqual(self.applicatie.autorisaties.count(), 1)
def test_noop_all_current_and_future_besluittypen(self): bt = BesluitTypeFactory.create() Autorisatie.objects.create( applicatie=self.applicatie, component=ComponentTypes.brc, scopes=["besluiten.lezen"], informatieobjecttype=f"http://testserver{bt.get_absolute_api_url()}", max_vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.beperkt_openbaar, ) data = { # management form "form-TOTAL_FORMS": 1, "form-INITIAL_FORMS": 0, "form-MIN_NUM_FORMS": 0, "form-MAX_NUM_FORMS": 1000, "form-0-component": ComponentTypes.brc, "form-0-scopes": ["besluiten.lezen"], "form-0-related_type_selection": RelatedTypeSelectionMethods.all_current_and_future, } response = self.client.post(self.url, data) self.assertEqual(response.status_code, 302) self.assertEqual(self.applicatie.autorisaties.count(), 1) # create a InformatieObjectType - this should trigger a new autorisatie # being installed BesluitTypeFactory.create() self.assertEqual(self.applicatie.autorisaties.count(), 2) # creating other types should not trigger anything, nor error ZaakTypeFactory.create() InformatieObjectTypeFactory.create() self.assertEqual(self.applicatie.autorisaties.count(), 2)
def test_add_autorisatie_all_current_informatieobjecttypen(self): iot1 = InformatieObjectTypeFactory.create(concept=False) iot2 = InformatieObjectTypeFactory.create(concept=True) data = { # management form "form-TOTAL_FORMS": 1, "form-INITIAL_FORMS": 0, "form-MIN_NUM_FORMS": 0, "form-MAX_NUM_FORMS": 1000, "form-0-component": ComponentTypes.drc, "form-0-scopes": ["documenten.lezen"], "form-0-related_type_selection": RelatedTypeSelectionMethods.all_current, "form-0-vertrouwelijkheidaanduiding": VertrouwelijkheidsAanduiding.beperkt_openbaar, } response = self.client.post(self.url, data) self.assertEqual(response.status_code, 302) self.assertEqual(Autorisatie.objects.count(), 2) self.assertEqual(self.applicatie.autorisaties.count(), 2) urls = [ reverse("informatieobjecttype-detail", kwargs={ "version": 1, "uuid": iot1.uuid }), reverse("informatieobjecttype-detail", kwargs={ "version": 1, "uuid": iot2.uuid }), ] for autorisatie in Autorisatie.objects.all(): with self.subTest(autorisatie=autorisatie): self.assertEqual(autorisatie.component, ComponentTypes.drc) self.assertEqual(autorisatie.scopes, ["documenten.lezen"]) self.assertEqual( autorisatie.max_vertrouwelijkheidaanduiding, VertrouwelijkheidsAanduiding.beperkt_openbaar, ) self.assertIsInstance(autorisatie.informatieobjecttype, str) parsed = urlparse(autorisatie.informatieobjecttype) self.assertEqual(parsed.scheme, "http") self.assertEqual(parsed.netloc, "testserver") self.assertIn(parsed.path, urls)
def test_besluittype_external_iotype_internal(self): catalogus = f"{self.base}catalogussen/1c8e36be-338c-4c07-ac5e-1adf55bec04a" besluittype = f"{self.base}besluittypen/b71f72ef-198d-44d8-af64-ae1932df830a" besluit = BesluitFactory.create(besluittype=besluittype) besluit_url = f"http://openbesluit.nl{reverse(besluit)}" informatieobjecttype = InformatieObjectTypeFactory.create() eio_response = get_eio_response( self.document, informatieobjecttype=f"http://openbesluit.nl{reverse(informatieobjecttype)}", ) with requests_mock.Mocker(real_http=True) as m: m.get(besluittype, json=get_besluittype_response(catalogus, besluittype)) m.get(self.document, json=eio_response) response = self.client.post( self.list_url, {"besluit": besluit_url, "informatieobject": self.document}, HTTP_HOST="openbesluit.nl", ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual( error["code"], "missing-besluittype-informatieobjecttype-relation" )
def test_create_bio_fail_invalid_schema(self): base = "https://external.documenten.nl/api/v1/" document = f"{base}enkelvoudiginformatieobjecten/{uuid.uuid4()}" besluit = BesluitFactory.create(besluittype__concept=False) besluit_url = f"http://openzaak.nl{reverse(besluit)}" informatieobjecttype = InformatieObjectTypeFactory.create( catalogus=besluit.besluittype.catalogus, concept=False ) informatieobjecttype_url = f"http://openzaak.nl{reverse(informatieobjecttype)}" informatieobjecttype.besluittypen.add(besluit.besluittype) with requests_mock.Mocker(real_http=True) as m: m.get( document, json={ "url": document, "beschrijving": "", "ontvangstdatum": None, "informatieobjecttype": informatieobjecttype_url, "locked": False, }, ) response = self.client.post( self.list_url, {"besluit": besluit_url, "informatieobject": document}, ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "informatieobject") self.assertEqual(error["code"], "invalid-resource")
def test_informatieobject_create(self): eio_url = reverse(EnkelvoudigInformatieObject) informatieobjecttype = InformatieObjectTypeFactory.create(concept=True) informatieobjecttype_url = reverse(informatieobjecttype) content = { "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(eio_url, content) # Test response self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data)
def test_create_two_docs_with_same_identificatie_and_bronorganisatie(self): informatieobjecttype = InformatieObjectTypeFactory.create( concept=False) informatieobjecttype_url = reverse(informatieobjecttype) content = { "identificatie": "12345", "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) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data) response = self.client.post(self.list_url, content) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data) self.assertEqual(len(response.data["invalid_params"]), 1) self.assertEqual(response.data["invalid_params"][0]["code"], "identificatie-niet-uniek")
def test_create_document_no_url_mapping(self): # Remove all available mappings UrlMapping.objects.all().delete() iot = InformatieObjectTypeFactory.create(concept=False) iot_url = f"http://testserver{reverse(iot)}" 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": iot_url, "vertrouwelijkheidaanduiding": "openbaar", } # Send to the API response = self.client.post(reverse(EnkelvoudigInformatieObject), content) # Test response self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data) self.assertEqual( response.data["detail"], "CMIS-adapter could not shrink one of the URL fields.", )
def test_zaaktype_internal_iotype_internal_fail(self): zaak = ZaakFactory.create() zaak_url = f"http://openzaak.nl{reverse(zaak)}" informatieobjecttype = InformatieObjectTypeFactory.create() eio_response = get_eio_response( self.document, informatieobjecttype= f"http://openzaak.nl{reverse(informatieobjecttype)}", ) with requests_mock.Mocker(real_http=True) as m: m.get(self.document, json=eio_response) response = self.client.post( self.list_url, { "zaak": zaak_url, "informatieobject": self.document }, HTTP_HOST="openzaak.nl", ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "missing-zaaktype-informatieobjecttype-relation")
def _create_enkelvoudiginformatieobject(self, **HEADERS): informatieobjecttype = InformatieObjectTypeFactory.create( concept=False) 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", } response = self.client.post(self.informatieobject_list_url, content, **HEADERS) return response.data
def test_create_document_with_binary_content(self): informatieobjecttype = InformatieObjectTypeFactory.create(concept=False) 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"%PDF-1.4\n%\xc3\xa4\xc3\xbc\xc3\xb6\n2 0 obj\n<</Length 3 0 R/Filter/FlateDecode>>\nstream\nx\x9c" ).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 storage backend (Alfresco) self.assertEqual(EnkelvoudigInformatieObject.objects.count(), 1) stored_object = EnkelvoudigInformatieObject.objects.get() self.assertEqual( stored_object.inhoud.read(), b"%PDF-1.4\n%\xc3\xa4\xc3\xbc\xc3\xb6\n2 0 obj\n<</Length 3 0 R/Filter/FlateDecode>>\nstream\nx\x9c", )
def test_destroy_with_external_informatieobject(self): oio = f"{self.base}objectinformatieobjecten/{uuid.uuid4()}" informatieobjecttype = InformatieObjectTypeFactory.create() with requests_mock.Mocker(real_http=True) as m: mock_service_oas_get(m, APITypes.drc, self.base) m.get( self.document, json=get_eio_response( self.document, informatieobjecttype=f"http://openzaak.nl{reverse(informatieobjecttype)}", ), ) m.delete(oio, status_code=204) bio = BesluitInformatieObjectFactory.create( informatieobject=self.document, _objectinformatieobject_url=oio ) bio_url = reverse(bio) response = self.client.delete(bio_url, HTTP_HOST="openzaak.nl") self.assertEqual( response.status_code, status.HTTP_204_NO_CONTENT, response.data ) self.assertEqual(BesluitInformatieObject.objects.count(), 0) history_delete = [ req for req in m.request_history if req.method == "DELETE" and req.url == oio ] self.assertEqual(len(history_delete), 1)
def test_integrity_empty(self): """ Assert that integrity is optional. """ informatieobjecttype = InformatieObjectTypeFactory.create( concept=False) informatieobjecttype_url = reverse(informatieobjecttype) content = { "identificatie": uuid.uuid4().hex, "bronorganisatie": "159351741", "creatiedatum": "2018-12-13", "titel": "Voorbeelddocument", "auteur": "test_auteur", "formaat": "text/plain", "taal": "eng", "bestandsnaam": "dummy.txt", "vertrouwelijkheidaanduiding": "openbaar", "inhoud": b64encode(b"some file content").decode("utf-8"), "informatieobjecttype": f"http://testserver{informatieobjecttype_url}", "integriteit": None, } # Send to the API response = self.client.post(self.list_url, content) self.assertEqual(response.status_code, status.HTTP_201_CREATED) stored_object = EnkelvoudigInformatieObject.objects.get() self.assertEqual(stored_object.integriteit, { "algoritme": "", "waarde": "", "datum": None })
def test_create_ignores_lock(self): informatieobjecttype = InformatieObjectTypeFactory.create( concept=False) 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": f"http://testserver{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)
def test_destroy_with_external_informatieobject_fail_send(self): oio = f"{self.base}objectinformatieobjecten/{uuid.uuid4()}" informatieobjecttype = InformatieObjectTypeFactory.create() with requests_mock.Mocker(real_http=True) as m: mock_service_oas_get(m, APITypes.drc, self.base) m.get( self.document, json=get_eio_response( self.document, informatieobjecttype=f"http://openzaak.nl{reverse(informatieobjecttype)}", ), ) m.delete(oio, status_code=404, text="Not found") bio = BesluitInformatieObjectFactory.create( informatieobject=self.document, _objectinformatieobject_url=oio ) bio_url = reverse(bio) response = self.client.delete(bio_url, HTTP_HOST="openzaak.nl") self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "informatieobject") self.assertEqual(error["code"], "pending-relations")
def test_inhoud_correct_padding(self): iotype = InformatieObjectTypeFactory.create(concept=False) iotype_url = reverse(iotype) url = reverse("enkelvoudiginformatieobject-list") content = { "identificatie": uuid.uuid4().hex, "bronorganisatie": "159351741", "creatiedatum": "2018-06-27", "titel": "detailed summary", "auteur": "test_auteur", "formaat": "txt", "taal": "eng", "bestandsnaam": "dummy.txt", # Remove padding from the base64 data "inhoud": b64encode(b"some file content").decode("utf-8"), "link": "http://een.link", "beschrijving": "test_beschrijving", "informatieobjecttype": f"http://testserver{iotype_url}", "vertrouwelijkheidaanduiding": "openbaar", } # Send to the API response = self.client.post(url, content) self.assertEqual(response.status_code, status.HTTP_201_CREATED)
def test_ontvangen_informatieobjecten(self): """ Assert certain statuses are not allowed for received documents. RGBZ 2.00.02 deel II Concept 20180613: De waarden ?in bewerking? en ?ter vaststelling? zijn niet van toepassing op ontvangen informatieobjecten. """ informatieobjecttype = InformatieObjectTypeFactory.create( concept=False) informatieobjecttype_url = reverse(informatieobjecttype) invalid_statuses = (Statussen.in_bewerking, Statussen.ter_vaststelling) data = { "bronorganisatie": "319582462", "creatiedatum": "2018-12-24", "titel": "dummy", "auteur": "dummy", "taal": "nld", "inhoud": "aGVsbG8gd29ybGQ=", "informatieobjecttype": f"http://testserver{informatieobjecttype_url}", "ontvangstdatum": "2018-12-24", } for invalid_status in invalid_statuses: with self.subTest(status=invalid_status): _data = data.copy() _data["status"] = invalid_status response = self.client.post(self.url, _data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "status") self.assertEqual(error["code"], "invalid_for_received")
def test_page_returns_on_get(self): # set up some initial data iot = InformatieObjectTypeFactory.create() Autorisatie.objects.create( applicatie=self.applicatie, component=ComponentTypes.drc, scopes=["documenten.lezen"], max_vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding. openbaar, informatieobjecttype=build_absolute_url( iot.get_absolute_api_url()), ) AutorisatieSpecFactory.create( applicatie=self.applicatie, component=ComponentTypes.brc, scopes=["besluiten.lezen"], ) Autorisatie.objects.create( applicatie=self.applicatie, component=ComponentTypes.nrc, scopes=["notificaties.consumeren"], ) response = self.client.get(self.url) self.assertEqual(response.status_code, 200)
def _create_informatieobject(self): informatieobjecttype = InformatieObjectTypeFactory.create(concept=False) canonical = EnkelvoudigInformatieObjectCanonicalFactory.create( latest_version=None ) add_url = reverse("admin:documenten_enkelvoudiginformatieobject_add") data = { "uuid": uuid.uuid4(), "_informatieobjecttype": informatieobjecttype.id, "canonical": canonical.id, "bronorganisatie": "517439943", "creatiedatum": "15-11-2019", "titel": "detailed summary", "auteur": "test_auteur", "formaat": "txt", "taal": "eng", "bestandsnaam": "dummy.txt", "inhoud": SimpleUploadedFile("file_name.txt", b"file contents"), "beschrijving": "desc", "versie": 1, } self.client.post(add_url, data) self.assertEqual(EnkelvoudigInformatieObject.objects.count(), 1) return EnkelvoudigInformatieObject.objects.get()
def test_vertrouwelijkheidaanduiding_explicit(self): """ Assert the explicit set of vertrouwelijkheidaanduiding """ informatieobjecttype = InformatieObjectTypeFactory.create( vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding. zaakvertrouwelijk) informatieobjecttype_url = reverse(informatieobjecttype) url = reverse("enkelvoudiginformatieobject-list") response = self.client.post( url, { "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", }, ) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual( response.data["vertrouwelijkheidaanduiding"], VertrouwelijkheidsAanduiding.openbaar, )
def test_inhoud_invalid_utf8_char_not_b64_encoded(self): informatieobjecttype = InformatieObjectTypeFactory.create( concept=False) 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": "<", "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_400_BAD_REQUEST)
def test_create_without_identificatie(self): informatieobjecttype = InformatieObjectTypeFactory.create( concept=False) informatieobjecttype_url = reverse(informatieobjecttype) content = { "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 stored_object = EnkelvoudigInformatieObject.objects.get() self.assertEqual(EnkelvoudigInformatieObject.objects.count(), 1) # Test generation of human readable identificatie self.assertEqual(stored_object.identificatie, "DOCUMENT-2018-0000000001")
def test_create_fail_informatieobjecttype_max_length(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/some-very-long-url-addres-which-exceeds-maximum-" f"length-of-hyperlinkedrelatedfield/aaaaaaaaaaaaaaaaaaaaaaaaa/" f"{informatieobjecttype_url}", "vertrouwelijkheidaanduiding": "openbaar", } # 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, "informatieobjecttype") self.assertEqual(error["code"], "max_length")
def setUpTestData(cls): cls.informatieobjecttype = InformatieObjectTypeFactory.create() site = Site.objects.get_current() site.domain = "testserver" site.save() super().setUpTestData()
def test_eio_create_fail_send_notification_create_db_entry(self): url = get_operation_url("enkelvoudiginformatieobject_create") informatieobjecttype = InformatieObjectTypeFactory.create( concept=False) informatieobjecttype_url = reverse(informatieobjecttype) 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": base64.b64encode(b"some file content").decode("utf-8"), "link": "http://een.link", "beschrijving": "test_beschrijving", "informatieobjecttype": f"http://testserver{informatieobjecttype_url}", "vertrouwelijkheidaanduiding": "openbaar", } with capture_on_commit_callbacks(execute=True): response = self.client.post(url, data) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data) data = response.json() self.assertEqual(StatusLog.objects.count(), 1) logged_warning = StatusLog.objects.get() failed = FailedNotification.objects.get() message = { "aanmaakdatum": "2019-01-01T12:00:00Z", "actie": "create", "hoofdObject": data["url"], "kanaal": "documenten", "kenmerken": { "bronorganisatie": "159351741", "informatieobjecttype": f"http://testserver{informatieobjecttype_url}", "vertrouwelijkheidaanduiding": "openbaar", }, "resource": "enkelvoudiginformatieobject", "resourceUrl": data["url"], } self.assertEqual(failed.statuslog_ptr, logged_warning) self.assertEqual(failed.message, message)
def test_send_notif_create_enkelvoudiginformatieobject(self, mock_client): """ Registreer een ENKELVOUDIGINFORMATIEOBJECT """ informatieobjecttype = InformatieObjectTypeFactory.create( concept=False) 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": f"http://testserver{informatieobjecttype_url}", "vertrouwelijkheidaanduiding": VertrouwelijkheidsAanduiding.openbaar, } with capture_on_commit_callbacks(execute=True): 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, }, }, )
def test_bio_visibility_outside_transaction(self): self.setUpTestData() document = f"{self.base}enkelvoudiginformatieobjecten/{uuid.uuid4()}" besluit = BesluitFactory.create(besluittype__concept=False) besluit_url = f"http://openzaak.nl{reverse(besluit)}" informatieobjecttype = InformatieObjectTypeFactory.create( catalogus=besluit.besluittype.catalogus, concept=False ) informatieobjecttype_url = f"http://openzaak.nl{reverse(informatieobjecttype)}" informatieobjecttype.besluittypen.add(besluit.besluittype) eio_response = get_eio_response( document, informatieobjecttype=informatieobjecttype_url ) def worker(besluit_id: int): """ Worker to run in a thread. When this worker runs, there should be one ZIO visible in the database - it must have been committed so that the remote DRC can view this record too. """ bios = BesluitInformatieObject.objects.filter(besluit__id=besluit_id) self.assertEqual(bios.count(), 1) close_old_connections() def mock_create_remote_oio(*args, **kwargs): with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor: future = executor.submit(worker, besluit.id) future.result() # raises any exceptions, such as assertionerrors return {"url": f"{self.base}objectinformatieobjecten/{uuid.uuid4()}"} with patch( "openzaak.components.besluiten.api.serializers.create_remote_oio", side_effect=mock_create_remote_oio, ): with requests_mock.Mocker() as m: mock_service_oas_get( m, APITypes.drc, self.base, oas_url=settings.DRC_API_SPEC ) m.get(document, json=eio_response) response = self.client.post( self.list_url, {"besluit": besluit_url, "informatieobject": document}, ) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data)
def test_validate_informatieobjecttype_unpublished(self): informatieobjecttype = InformatieObjectTypeFactory.create() informatieobjecttype_url = reverse(informatieobjecttype) url = reverse("enkelvoudiginformatieobject-list") response = self.client.post( url, { "informatieobjecttype": f"http://testserver{informatieobjecttype_url}" }, ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "informatieobjecttype") self.assertEqual(error["code"], "not-published")