Skip to content

Commit

Permalink
[#3607] PR feedback 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Jan 4, 2024
1 parent a13d020 commit f504f53
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/openforms/contrib/brk/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BRKValidatorCheck:
def check_config():
try:
with get_client() as client:
results = client.get_cadastrals_by_address(
results = client.get_real_estate_by_address(
{"postcode": "1234AB", "huisnummer": "1"}
)
except NoServiceConfigured as exc:
Expand Down
6 changes: 3 additions & 3 deletions src/openforms/contrib/brk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class SearchParams(TypedDict):


class BRKClient(APIClient):
def get_cadastrals_by_address(self, query_params: SearchParams):
def get_real_estate_by_address(self, query_params: SearchParams):
"""
Search for cadastrals by querying for a specifc address.
Search for real estate by querying for a specific address.
API docs: https://vng-realisatie.github.io/Haal-Centraal-BRK-bevragen/swagger-ui-2.0#/Kadastraal%20Onroerende%20Zaken/GetKadastraalOnroerendeZaken
"""
Expand All @@ -55,7 +55,7 @@ def get_cadastrals_by_address(self, query_params: SearchParams):

def get_cadastral_titleholders_by_cadastral_id(self, cadastral_id: str):
"""
Search for commercial titleholders of a cadastral immovable property.
Look up the rightholders of a property (e.g. a house) in the Dutch cadastre.
API docs: https://vng-realisatie.github.io/Haal-Centraal-BRK-bevragen/swagger-ui-2.0#/Zakelijke%20Gerechtigden/GetZakelijkGerechtigden
"""
Expand Down
10 changes: 10 additions & 0 deletions src/openforms/contrib/brk/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import TypedDict

from typing_extensions import NotRequired


class AddressValue(TypedDict):
postcode: str
house_number: str
house_letter: NotRequired[str]
house_number_addition: NotRequired[str]
8 changes: 4 additions & 4 deletions src/openforms/contrib/brk/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BRKCadastralClientTests(OFVCRMixin, BRKTestMixin, SimpleTestCase):
def test_client(self):

with get_client() as client:
res = client.get_cadastrals_by_address(
res = client.get_real_estate_by_address(
{"postcode": "7361EW", "huisnummer": "21"}
)

Expand All @@ -28,7 +28,7 @@ def test_client(self):

def test_client_404(self):
with get_client() as client:
res = client.get_cadastrals_by_address(
res = client.get_real_estate_by_address(
{"postcode": "1234AB", "huisnummer": "1"} # Does not exist
)
self.assertEqual(res["_embedded"], {})
Expand All @@ -39,7 +39,7 @@ def test_client_500(self, m):

with get_client() as client:
with self.assertRaises(requests.RequestException):
client.get_cadastrals_by_address(
client.get_real_estate_by_address(
{"postcode": "1234AA", "huisnummer": "123"}
)

Expand Down Expand Up @@ -71,4 +71,4 @@ def test_client_500(self, m):

with get_client() as client:
with self.assertRaises(requests.RequestException):
client.get_cadastrals_by_address("cadastral_id")
client.get_real_estate_by_address("cadastral_id")
1 change: 1 addition & 0 deletions src/openforms/contrib/brk/tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def test_brk_validator_requests_error(self, m: requests_mock.Mocker):

class BRKValidatorNotConfiguredTestCase(TestCase):
def setUp(self):
super().setUp()

patcher = patch(
"openforms.contrib.brk.client.BRKConfig.get_solo",
Expand Down
13 changes: 3 additions & 10 deletions src/openforms/contrib/brk/validators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from contextlib import contextmanager
from typing import Iterator, TypedDict
from typing import Iterator

from django.core.exceptions import ValidationError
from django.utils.deconstruct import deconstructible
Expand All @@ -9,13 +9,13 @@
from glom import glom
from requests import RequestException
from rest_framework import serializers
from typing_extensions import NotRequired

from openforms.authentication.constants import AuthAttribute
from openforms.submissions.models import Submission
from openforms.validations.registry import register

from .client import NoServiceConfigured, SearchParams, get_client
from .constants import AddressValue

logger = logging.getLogger(__name__)

Expand All @@ -31,13 +31,6 @@ def suppress_api_errors(error_message: str) -> Iterator[None]:
raise ValidationError(error_message) from e


class AddressValue(TypedDict):
postcode: str
house_number: str
house_letter: NotRequired[str]
house_number_addition: NotRequired[str]


class AddressValueSerializer(serializers.Serializer):
postcode = serializers.RegexField(
"^[1-9][0-9]{3} ?(?!sa|sd|ss|SA|SD|SS)[a-zA-Z]{2}$",
Expand Down Expand Up @@ -113,7 +106,7 @@ def __call__(self, value: AddressValue, submission: Submission) -> bool:
address_query["huisnummertoevoeging"] = value["house_number_addition"]

with (client, suppress_api_errors(self.error_messages["retrieving_error"])):
real_estate_objects_resp = client.get_cadastrals_by_address(address_query)
real_estate_objects_resp = client.get_real_estate_by_address(address_query)
real_estate_objects = glom(
real_estate_objects_resp,
"_embedded.kadastraalOnroerendeZaken",
Expand Down
4 changes: 3 additions & 1 deletion src/openforms/formio/formatters/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from django.utils.dateparse import parse_date, parse_datetime
from django.utils.html import format_html

from openforms.contrib.brk.constants import AddressValue

from ..typing import Component
from .base import FormatterBase

Expand All @@ -28,7 +30,7 @@ class AddressNLFormatter(FormatterBase):

empty_values = ({},)

def format(self, component: Component, value: dict[str, str]) -> str:
def format(self, component: Component, value: AddressValue) -> str:
value = value.copy()
value.setdefault("houseLetter", "")
value.setdefault("houseNumberAddition", "")
Expand Down
8 changes: 3 additions & 5 deletions src/openforms/validations/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from openforms.accounts.tests.factories import StaffUserFactory
from openforms.config.models import GlobalConfiguration
from openforms.submissions.constants import SUBMISSIONS_SESSION_KEY
from openforms.submissions.tests.factories import SubmissionFactory
from openforms.submissions.tests.mixins import SubmissionsMixin
from openforms.validations.registry import Registry, StringValueSerializer
from openforms.validations.tests.test_registry import (
DjangoValidator,
Expand All @@ -17,7 +17,7 @@
)


class ValidationsAPITests(APITestCase):
class ValidationsAPITests(SubmissionsMixin, APITestCase):
def setUp(self):
self.user = StaffUserFactory()
self.client.force_login(self.user)
Expand Down Expand Up @@ -168,9 +168,7 @@ def test_validation(self):
submission = SubmissionFactory.create()
submission_uuid = str(submission.uuid)
url = reverse("api:validate-value", kwargs={"validator": "django"})
session = self.client.session
session[SUBMISSIONS_SESSION_KEY] = [submission_uuid]
session.save()
self._add_submission_to_session(submission)

response = self.client.post(
url, {"value": "VALID", "submission_uuid": submission_uuid}, format="json"
Expand Down
2 changes: 1 addition & 1 deletion src/openforms/validations/tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_validate_plugin_not_enabled(self):
registry = Registry()
registry("disabled", "Disabled")(DisabledValidator())

res = registry.validate("disabled", "VALID", "dummy_submission")
res = registry.validate("disabled", "VALID", Submission())
self.assertEqual(res.is_valid, False)
self.assertEqual(
res.messages,
Expand Down

0 comments on commit f504f53

Please sign in to comment.