Skip to content

Commit

Permalink
Merge pull request #1398 from open-zaak/issue/1326-remove-local-services
Browse files Browse the repository at this point in the history
remove local services required configuration
  • Loading branch information
annashamray committed Jul 14, 2023
2 parents 2da5273 + 85b4230 commit a6df695
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 37 deletions.
6 changes: 4 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ commonground-api-common==1.10.2
# -r requirements/base.in
# drc-cmis
coreapi==2.3.3
# via drf-yasg
# via
# django-loose-fk
# drf-yasg
coreschema==0.0.4
# via
# coreapi
Expand Down Expand Up @@ -133,7 +135,7 @@ django-filter==21.1
# django-loose-fk
django-ipware==4.0.2
# via django-axes
django-loose-fk==1.0.2
django-loose-fk==1.0.3
# via -r requirements/base.in
django-markup==1.5
# via -r requirements/base.in
Expand Down
3 changes: 2 additions & 1 deletion requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ commonground-api-common==1.10.2
coreapi==2.3.3
# via
# -r requirements/base.txt
# django-loose-fk
# drf-yasg
coreschema==0.0.4
# via
Expand Down Expand Up @@ -176,7 +177,7 @@ django-ipware==4.0.2
# via
# -r requirements/base.txt
# django-axes
django-loose-fk==1.0.2
django-loose-fk==1.0.3
# via -r requirements/base.txt
django-markup==1.5
# via -r requirements/base.txt
Expand Down
3 changes: 2 additions & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ commonmark==0.9.1
coreapi==2.3.3
# via
# -r requirements/ci.txt
# django-loose-fk
# drf-yasg
coreschema==0.0.4
# via
Expand Down Expand Up @@ -203,7 +204,7 @@ django-ipware==4.0.2
# via
# -r requirements/ci.txt
# django-axes
django-loose-fk==1.0.2
django-loose-fk==1.0.3
# via -r requirements/ci.txt
django-markup==1.5
# via -r requirements/ci.txt
Expand Down
11 changes: 7 additions & 4 deletions src/openzaak/components/besluiten/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _

from django_loose_fk.virtual_models import ProxyMixin
from vng_api_common.fields import RSINField
from vng_api_common.models import APIMixin
from vng_api_common.utils import generate_unique_identification
Expand Down Expand Up @@ -195,10 +196,12 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

# save previous zaak for triggers
# self._previous_zaak = self.zaak

self._previous_zaak = self._zaak
self._previous_zaak_url = self._zaak_url
# for virtual models we can't use FK field because of handler assertions
if isinstance(self, ProxyMixin):
self._previous_zaak = self.zaak
else:
self._previous_zaak = self._zaak
self._previous_zaak_url = self._zaak_url

def __str__(self):
return f"{self.verantwoordelijke_organisatie} - {self.identificatie}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,7 @@ def test_bio_visibility_outside_transaction(self):
self.setUpTestData()
document = f"{self.base}enkelvoudiginformatieobjecten/{uuid.uuid4()}"

besluit = BesluitFactory.create(
besluittype__concept=False, local_host="http://openzaak.nl/"
)
besluit = BesluitFactory.create(besluittype__concept=False)
besluit_url = f"http://openzaak.nl{reverse(besluit)}"
informatieobjecttype = InformatieObjectTypeFactory.create(
catalogus=besluit.besluittype.catalogus, concept=False
Expand Down Expand Up @@ -660,9 +658,7 @@ def test_destroy_with_external_informatieobject(self):
m.delete(oio, status_code=204)

bio = BesluitInformatieObjectFactory.create(
informatieobject=self.document,
_objectinformatieobject_url=oio,
local_host="http://openzaak.nl",
informatieobject=self.document, _objectinformatieobject_url=oio,
)
bio_url = reverse(bio)

Expand Down Expand Up @@ -696,9 +692,7 @@ def test_destroy_with_external_informatieobject_fail_send(self):
m.delete(oio, status_code=404, text="Not found")

bio = BesluitInformatieObjectFactory.create(
informatieobject=self.document,
_objectinformatieobject_url=oio,
local_host="http://openzaak.nl",
informatieobject=self.document, _objectinformatieobject_url=oio,
)
bio_url = reverse(bio)

Expand Down
3 changes: 3 additions & 0 deletions src/openzaak/components/documenten/tests/test_caching_cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from rest_framework import status
from vng_api_common.tests import CacheMixin, JWTAuthMixin, reverse
from zgw_consumers.constants import APITypes
from zgw_consumers.models import Service

from openzaak.components.zaken.tests.factories import ZaakInformatieObjectFactory
from openzaak.tests.utils import (
Expand Down Expand Up @@ -217,6 +219,7 @@ def test_invalidate_etag_after_change(self):
Because changes are made to the informatieobject, a code 200 should be
returned
"""
Service.objects.create(api_root="http://testserver/", api_type=APITypes.orc)
eio = EnkelvoudigInformatieObjectFactory.create(titel="bla")

key = get_etag_cache_key(eio)
Expand Down
2 changes: 1 addition & 1 deletion src/openzaak/components/zaken/tests/test_zaak_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ def test_add_resultaat_on_zaak_with_external_gerelateerde_zaak_(self):
"""
Add RESULTAAT that causes `archiefactiedatum` to be set.
"""
zaak = ZaakFactory.create(local_host="http://testserver.com")
zaak = ZaakFactory.create()
zaak_url = get_operation_url("zaak_read", uuid=zaak.uuid)
zaaktype_url = f"http://testserver.com{reverse(zaak.zaaktype)}"

Expand Down
23 changes: 16 additions & 7 deletions src/openzaak/components/zaken/tests/test_zaak_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
from zgw_consumers.test import mock_service_oas_get

from openzaak.components.besluiten.tests.factories import BesluitFactory
from openzaak.components.catalogi.tests.factories import (
InformatieObjectTypeFactory,
ZaakTypeFactory,
)
from openzaak.tests.utils import JWTAuthMixin, get_eio_response

from ..models import (
Expand Down Expand Up @@ -137,20 +141,25 @@ def setUpTestData(cls):

@requests_mock.Mocker()
def test_zaak_delete_oio_removed(self, m):
# setup resources amd mocks
document_url = f"{self.base}enkelvoudiginformatieobjecten/{uuid.uuid4()}"
zaaktype = ZaakTypeFactory()
iotype = InformatieObjectTypeFactory(
zaaktypen=[zaaktype], catalogus=zaaktype.catalogus
)
zaak = ZaakFactory.create(zaaktype=zaaktype)
mock_service_oas_get(m, self.base, APITypes.drc)
document = f"{self.base}enkelvoudiginformatieobjecten/{uuid.uuid4()}"
eio_response = get_eio_response(
document,
informatieobjecttype="http://testserver/catalogi/api/v1/iot/dummy",
document_data = get_eio_response(
document_url, informatieobjecttype=f"http://testserver{reverse(iotype)}"
)
m.get(document, json=eio_response)
zaak = ZaakFactory.create()
m.get(document_url, json=document_data)
zio = ZaakInformatieObjectFactory.create(
zaak=zaak,
informatieobject=document,
informatieobject=document_url,
_objectinformatieobject_url=f"{self.base}_objectinformatieobjecten/{uuid.uuid4()}",
)
m.delete(zio._objectinformatieobject_url, status_code=204)

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

with self.captureOnCommitCallbacks(execute=True):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ def test_filter_by_external_informatieobject(self):
zio_type = ZaakTypeInformatieObjectTypeFactory.create(
informatieobjecttype__concept=False, zaaktype__concept=False
)
zaak = ZaakFactory.create(
zaaktype=zio_type.zaaktype, local_host="http://openzaak.nl"
)
zaak = ZaakFactory.create(zaaktype=zio_type.zaaktype)
zaak_url = f"http://openzaak.nl{reverse(zaak)}"

eio1_response = get_eio_response(
Expand Down
5 changes: 5 additions & 0 deletions src/openzaak/tests/utils/cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from drc_cmis.client_builder import get_cmis_client
from drc_cmis.models import CMISConfig, UrlMapping
from rest_framework.test import APITestCase, APITransactionTestCase
from zgw_consumers.constants import APITypes
from zgw_consumers.models import Service

from .helpers import can_connect
from .mocks import MockSchemasMixin, get_eio_response
Expand Down Expand Up @@ -90,6 +92,9 @@ def setUpTestData(cls):
config=config,
)

# add local service configuration - required for composite urls
Service.objects.create(api_root="http://testserver/", api_type=APITypes.orc)

def setUp(self) -> None:
# real_http=True to let the other calls pass through and use a different mocker
# in specific tests cases to catch those requests
Expand Down
9 changes: 0 additions & 9 deletions src/openzaak/tests/utils/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
class FkOrServiceUrlFactoryMixin:
"""
create service instances for composite url fields
create service for provided parameter 'local_host'
"""

local_host = "http://testserver/" # use to create service for local api

@classmethod
def _create(cls, model_class, *args, **kwargs):
"""
Expand All @@ -38,12 +35,6 @@ def _create(cls, model_class, *args, **kwargs):
# create Service instance for composite field
base_url = furl(value).origin
services.append(Service(api_root=base_url, api_type=APITypes.orc))
# service, created = Service.objects.get_or_create(api_root=base_url, defaults={"api_type": APITypes.orc})

# if local host specified create service for it
local_host = kwargs.pop("local_host", cls.local_host)
if local_host:
services.append(Service(api_root=local_host, api_type=APITypes.orc))

Service.objects.bulk_create(services, ignore_conflicts=True)

Expand Down

0 comments on commit a6df695

Please sign in to comment.