Skip to content

Commit

Permalink
[#3607] Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Jan 4, 2024
1 parent e5639bb commit f7634c8
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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
69 changes: 69 additions & 0 deletions src/openforms/contrib/brk/tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 0 additions & 9 deletions src/openforms/contrib/brk/tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit f7634c8

Please sign in to comment.