diff --git a/src/openforms/contrib/brk/tests/files/vcr_cassettes/BRKValidatorIntegrationTestCase/BRKValidatorIntegrationTestCase.test_brk_validator_integration.yaml b/src/openforms/contrib/brk/tests/files/vcr_cassettes/BRKValidatorIntegrationTestCase/BRKValidatorIntegrationTestCase.test_brk_validator_integration.yaml new file mode 100644 index 0000000000..efc877dbfc --- /dev/null +++ b/src/openforms/contrib/brk/tests/files/vcr_cassettes/BRKValidatorIntegrationTestCase/BRKValidatorIntegrationTestCase.test_brk_validator_integration.yaml @@ -0,0 +1,40 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Connection: + - keep-alive + User-Agent: + - python-requests/2.31.0 + X-Api-Key: + - fake_changeme_when_testing + method: GET + uri: https://api.brk.kadaster.nl/esd-eto-apikey/bevragen/v2/kadastraalonroerendezaken?postcode=1234AB&huisnummer=1&huisletter=A&huisnummertoevoeging=Add + response: + body: + string: '{"_links":{"self":{"href":"/kadastraalonroerendezaken?postcode=1234AB&huisnummer=1&huisletter=A&huisnummertoevoeging=Add"}},"_embedded":{}}' + headers: + Api-Version: + - 2.0.0 + Connection: + - keep-alive + Content-Encoding: + - gzip + Content-Length: + - '133' + Content-Type: + - application/hal+json + Date: + - Thu, 04 Jan 2024 16:15:08 GMT + Keep-Alive: + - timeout=60 + Server: + - Unspecified + status: + code: 200 + message: '' +version: 1 diff --git a/src/openforms/contrib/brk/tests/test_integration.py b/src/openforms/contrib/brk/tests/test_integration.py new file mode 100644 index 0000000000..f09e54834c --- /dev/null +++ b/src/openforms/contrib/brk/tests/test_integration.py @@ -0,0 +1,69 @@ +from unittest.mock import patch + +from django.utils.translation import gettext_lazy as _ + +from rest_framework.reverse import reverse +from rest_framework.test import APITestCase + +from openforms.authentication.constants import AuthAttribute +from openforms.submissions.tests.factories import SubmissionFactory +from openforms.submissions.tests.mixins import SubmissionsMixin +from openforms.utils.tests.vcr import OFVCRMixin +from openforms.validations.registry import Registry + +from ..validators import BRKZakelijkGerechtigdeValidator +from .base import TEST_FILES, BRKTestMixin + + +class BRKValidatorIntegrationTestCase( + SubmissionsMixin, OFVCRMixin, BRKTestMixin, APITestCase +): + VCR_TEST_FILES = TEST_FILES + + def setUp(self) -> None: + super().setUp() + register = Registry() + register( + "brk-zakelijk-gerechtigd", + verbose_name="dummy", + for_components=("addressNL",), + )(BRKZakelijkGerechtigdeValidator) + + patcher = patch("openforms.validations.api.views.register", new=register) + patcher.start() + self.addCleanup(patcher.stop) + + def test_brk_validator_integration(self) -> None: + submission = SubmissionFactory.create( + form__generate_minimal_setup=True, + form__authentication_backends=["demo"], + form__formstep__form_definition__login_required=False, + auth_info__attribute_hashed=False, + auth_info__attribute=AuthAttribute.bsn, + auth_info__value="12345678", + auth_info__plugin="demo", + ) + self._add_submission_to_session(submission) + + response = self.client.post( + reverse( + "api:validate-value", kwargs={"validator": "brk-zakelijk-gerechtigd"} + ), + { + "value": { + "postcode": "1234 aB", + "house_number": "1", + "house_letter": "A", + "house_number_addition": "Add", + }, + "submission_uuid": str(submission.uuid), + }, + format="json", + ) + + expected = { + "is_valid": False, + "messages": [_("No property found for this address.")], + } + self.assertEqual(response.status_code, 200) + self.assertEqual(response.data, expected) diff --git a/src/openforms/contrib/brk/tests/test_validators.py b/src/openforms/contrib/brk/tests/test_validators.py index e969ebd6fe..a86ae4acec 100644 --- a/src/openforms/contrib/brk/tests/test_validators.py +++ b/src/openforms/contrib/brk/tests/test_validators.py @@ -20,15 +20,6 @@ class BRKValidatorTestCase(OFVCRMixin, BRKTestMixin, TestCase): VCR_TEST_FILES = TEST_FILES - def test_brk_validator_serializer(self): - serializer = BRKZakelijkGerechtigdeValidator.value_serializer( - data={"value": {"postcode": "1234 aB", "house_number": "1"}} - ) - serializer.is_valid(raise_exception=True) - self.assertEqual( - serializer.data, {"value": {"postcode": "1234AB", "house_number": "1"}} - ) - def test_brk_validator_no_auth(self): validator = BRKZakelijkGerechtigdeValidator()