def test_besluittype_external_iotype_external_success(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 = f"{self.base}informatieobjecttypen/{uuid.uuid4()}" besluittype_data = get_besluittype_response(catalogus, besluittype) besluittype_data["informatieobjecttypen"] = [informatieobjecttype] with requests_mock.Mocker(real_http=True) as m: mock_service_oas_get(m, APITypes.drc, self.base) m.get(besluittype, json=besluittype_data) m.get( informatieobjecttype, json=get_informatieobjecttype_response(catalogus, informatieobjecttype), ) m.get( self.document, json=get_eio_response( self.document, informatieobjecttype=informatieobjecttype ), ) m.post( f"{self.base}objectinformatieobjecten", json=get_oio_response(self.document, besluit_url), status_code=201, ) response = self.client.post( self.list_url, {"besluit": besluit_url, "informatieobject": self.document}, HTTP_HOST="openbesluit.nl", ) self.assertEqual(response.status_code, status.HTTP_201_CREATED)
def test_zaaktype_external_iotype_external_success(self): catalogus = f"{self.base}catalogussen/1c8e36be-338c-4c07-ac5e-1adf55bec04a" zaaktype = f"{self.base}zaaktypen/b71f72ef-198d-44d8-af64-ae1932df830a" zaak = ZaakFactory.create(zaaktype=zaaktype) zaak_url = f"http://openzaak.nl{reverse(zaak)}" informatieobjecttype = f"{self.base}informatieobjecttypen/{uuid.uuid4()}" zaaktype_data = get_zaaktype_response(catalogus, zaaktype) zaaktype_data["informatieobjecttypen"] = [informatieobjecttype] with requests_mock.Mocker(real_http=True) as m: m.get(zaaktype, json=zaaktype_data) m.get( informatieobjecttype, json=get_informatieobjecttype_response(catalogus, informatieobjecttype), ) m.get( self.document, json=get_eio_response( self.document, informatieobjecttype=informatieobjecttype ), ) m.post( f"{self.base}objectinformatieobjecten", json=get_oio_response(self.document, zaak_url), status_code=201, ) response = self.client.post( self.list_url, {"zaak": zaak_url, "informatieobject": self.document}, HTTP_HOST="openzaak.nl", ) self.assertEqual(response.status_code, status.HTTP_201_CREATED)
def test_filter_by_external_informatieobject(self): base = "https://external.documenten.nl/api/v1/" document = f"{base}enkelvoudiginformatieobjecten/{uuid.uuid4()}" Service.objects.create( api_type=APITypes.drc, api_root=base, label="external documents", auth_type=AuthTypes.no_auth, ) zio_type = ZaakTypeInformatieObjectTypeFactory.create( informatieobjecttype__concept=False, zaaktype__concept=False) zaak = ZaakFactory.create(zaaktype=zio_type.zaaktype) zaak_url = f"http://openzaak.nl{reverse(zaak)}" eio_response = get_eio_response( document, informatieobjecttype= f"http://openzaak.nl{reverse(zio_type.informatieobjecttype)}", ) with requests_mock.Mocker(real_http=True) as m: mock_service_oas_get(m, APITypes.drc, base) m.get(document, json=eio_response) m.post( "https://external.documenten.nl/api/v1/objectinformatieobjecten", json=get_oio_response(document, zaak_url), status_code=201, ) response = self.client.post( reverse(ZaakInformatieObject), { "zaak": zaak_url, "informatieobject": document }, HTTP_HOST="openzaak.nl", ) io_url = response.data["informatieobject"] zio_list_url = reverse("zaakinformatieobject-list") response = self.client.get(zio_list_url, {"informatieobject": io_url}, HTTP_HOST="openzaak.nl") self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), 1) self.assertEqual(response.data[0]["informatieobject"], io_url)
def test_create_bio_external_document(self): 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 ) oio_response = get_oio_response(document, besluit_url, "besluit") with self.subTest(section="bio-create"): with requests_mock.Mocker(real_http=True) as m: mock_service_oas_get(m, APITypes.drc, self.base) m.get(document, json=eio_response) m.post( "https://external.documenten.nl/api/v1/objectinformatieobjecten", json=oio_response, status_code=201, ) response = self.client.post( self.list_url, {"besluit": besluit_url, "informatieobject": document}, ) self.assertEqual( response.status_code, status.HTTP_201_CREATED, response.data ) posts = [req for req in m.request_history if req.method == "POST"] self.assertEqual(len(posts), 1) request = posts[0] self.assertEqual( request.url, "https://external.documenten.nl/api/v1/objectinformatieobjecten", ) self.assertEqual( request.json(), { "informatieobject": document, "object": besluit_url, "objectType": "besluit", }, ) self.assertFalse(ObjectInformatieObject.objects.exists()) bio = BesluitInformatieObject.objects.get() self.assertEqual(bio._objectinformatieobject_url, oio_response["url"]) with self.subTest(section="bio-list"): list_response = self.client.get( self.list_url, {"besluit": besluit_url}, HTTP_HOST="openzaak.nl", ) self.assertEqual( list_response.status_code, status.HTTP_200_OK, response.data ) data = list_response.json() self.assertEqual(len(data), 1) self.assertEqual(data[0]["informatieobject"], document)
def test_relate_external_document(self): document = f"{self.base}enkelvoudiginformatieobjecten/{uuid.uuid4()}" zio_type = ZaakTypeInformatieObjectTypeFactory.create( informatieobjecttype__concept=False, zaaktype__concept=False) zaak = ZaakFactory.create(zaaktype=zio_type.zaaktype) zaak_url = f"http://openzaak.nl{reverse(zaak)}" eio_response = get_eio_response( document, informatieobjecttype= f"http://testserver{reverse(zio_type.informatieobjecttype)}", ) oio_response = get_oio_response(document, zaak_url) with self.subTest(section="zio-create"): with requests_mock.Mocker() as m: mock_service_oas_get(m, APITypes.drc, self.base) m.get(document, json=eio_response) m.post( "https://external.documenten.nl/api/v1/objectinformatieobjecten", json=oio_response, status_code=201, ) response = self.client.post( reverse(ZaakInformatieObject), { "zaak": zaak_url, "informatieobject": document }, ) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data) posts = [req for req in m.request_history if req.method == "POST"] self.assertEqual(len(posts), 1) request = posts[0] self.assertEqual( request.url, "https://external.documenten.nl/api/v1/objectinformatieobjecten", ) self.assertEqual( request.json(), { "informatieobject": document, "object": zaak_url, "objectType": "zaak", }, ) self.assertFalse(ObjectInformatieObject.objects.exists()) zio = ZaakInformatieObject.objects.get() self.assertEqual(zio._objectinformatieobject_url, oio_response["url"]) with self.subTest(section="zio-list"): list_response = self.client.get( reverse(ZaakInformatieObject), {"zaak": zaak_url}, HTTP_HOST="openzaak.nl", ) self.assertEqual(list_response.status_code, status.HTTP_200_OK) data = list_response.json() self.assertEqual(len(data), 1) self.assertEqual(data[0]["informatieobject"], document)