diff --git a/requirements/base.txt b/requirements/base.txt index 3679a30737..adb84cb8b9 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -62,7 +62,9 @@ cryptography==41.0.7 # mozilla-django-oidc # pyopenssl css-inline==0.13.0 - # via -r requirements/base.in + # via + # -r requirements/base.in + # mail-editor cssselect2==0.4.1 # via # svglib @@ -341,6 +343,7 @@ lockfile==0.12.2 lxml==4.9.1 # via # django-digid-eherkenning + # mail-editor # maykin-python3-saml # svglib # xmlsec @@ -453,6 +456,7 @@ requests==2.31.0 # django-open-forms-client # django-rosetta # gemma-zds-client + # mail-editor # maykin-python3-saml # messagebird # mozilla-django-oidc diff --git a/requirements/ci.txt b/requirements/ci.txt index efa1941572..1f2d0f9427 100644 --- a/requirements/ci.txt +++ b/requirements/ci.txt @@ -122,6 +122,7 @@ css-inline==0.13.0 # via # -c requirements/base.txt # -r requirements/base.txt + # mail-editor cssselect==1.1.0 # via pyquery cssselect2==0.4.1 @@ -605,6 +606,7 @@ lxml==4.9.1 # -c requirements/base.txt # -r requirements/base.txt # django-digid-eherkenning + # mail-editor # maykin-python3-saml # pyquery # svglib @@ -834,6 +836,7 @@ requests==2.31.0 # django-open-forms-client # django-rosetta # gemma-zds-client + # mail-editor # maykin-python3-saml # messagebird # mozilla-django-oidc diff --git a/requirements/dev.txt b/requirements/dev.txt index 516b552faf..27aea27803 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -147,6 +147,7 @@ css-inline==0.13.0 # via # -c requirements/ci.txt # -r requirements/ci.txt + # mail-editor cssselect==1.1.0 # via # -c requirements/ci.txt @@ -699,6 +700,7 @@ lxml==4.9.1 # -c requirements/ci.txt # -r requirements/ci.txt # django-digid-eherkenning + # mail-editor # maykin-python3-saml # pyquery # svglib @@ -974,6 +976,7 @@ requests==2.31.0 # django-rosetta # gemma-zds-client # locust + # mail-editor # maykin-python3-saml # messagebird # mozilla-django-oidc diff --git a/src/open_inwoner/accounts/tests/test_auth.py b/src/open_inwoner/accounts/tests/test_auth.py index 04d27c7994..5e828a5c9a 100644 --- a/src/open_inwoner/accounts/tests/test_auth.py +++ b/src/open_inwoner/accounts/tests/test_auth.py @@ -1079,12 +1079,12 @@ def test_eherkenning_user_success(self, mock_kvk): { "kvkNummer": "12345678", "vestigingsnummer": "1234", - "handelsnaam": "Mijn bedrijf", + "naam": "Mijn bedrijf", }, { "kvkNummer": "12345678", "vestigingsnummer": "5678", - "handelsnaam": "Mijn bedrijf", + "naam": "Mijn bedrijf", }, ] diff --git a/src/open_inwoner/kvk/client.py b/src/open_inwoner/kvk/client.py index df574e2a0c..600284a97e 100644 --- a/src/open_inwoner/kvk/client.py +++ b/src/open_inwoner/kvk/client.py @@ -68,15 +68,15 @@ def _request(self, endpoint: str, params: dict) -> dict: return data # - # Interface: search + # Interface # @cached_property def search_endpoint(self): - return self._urljoin(self.config.api_root, "zoeken") + return self._urljoin(self.config.api_root, "v2", "zoeken") @cached_property def basisprofielen_endpoint(self): - return self._urljoin(self.config.api_root, "basisprofielen") + return self._urljoin(self.config.api_root, "v1", "basisprofielen") def search(self, **kwargs) -> dict: """ diff --git a/src/open_inwoner/kvk/migrations/0003_api_root.py b/src/open_inwoner/kvk/migrations/0003_api_root.py new file mode 100644 index 0000000000..b505d8edf4 --- /dev/null +++ b/src/open_inwoner/kvk/migrations/0003_api_root.py @@ -0,0 +1,27 @@ +# Generated by Django 3.2.23 on 2024-02-12 08:12 + +from django.db import migrations + + +def strip_version_number(apps, _): + KvKConfig = apps.get_model("kvk.KvKConfig") + + config = KvKConfig.objects.first() + if not config: + return + + config.api_root = str(config.api_root).strip("v1/") + config.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("kvk", "0002_alter_kvkconfig_api_root"), + ] + + operations = [ + migrations.RunPython( + code=strip_version_number, reverse_code=migrations.RunPython.noop + ), + ] diff --git a/src/open_inwoner/kvk/migrations/0004_alter_kvkconfig_api_root.py b/src/open_inwoner/kvk/migrations/0004_alter_kvkconfig_api_root.py new file mode 100644 index 0000000000..911a5cb45b --- /dev/null +++ b/src/open_inwoner/kvk/migrations/0004_alter_kvkconfig_api_root.py @@ -0,0 +1,24 @@ +# Generated by Django 3.2.23 on 2024-02-19 08:26 + +from django.db import migrations, models +import open_inwoner.kvk.validators + + +class Migration(migrations.Migration): + + dependencies = [ + ("kvk", "0003_api_root"), + ] + + operations = [ + migrations.AlterField( + model_name="kvkconfig", + name="api_root", + field=models.URLField( + help_text="The root of the API without version number and endpoint (e.g. https://api.kvk.nl/api/ or https://api.kvk.nl/test/api).", + max_length=128, + validators=[open_inwoner.kvk.validators.validate_api_root], + verbose_name="API root", + ), + ), + ] diff --git a/src/open_inwoner/kvk/models.py b/src/open_inwoner/kvk/models.py index c648e658a7..294de34a7e 100644 --- a/src/open_inwoner/kvk/models.py +++ b/src/open_inwoner/kvk/models.py @@ -6,12 +6,18 @@ from simple_certmanager.models import Certificate from solo.models import SingletonModel +from .validators import validate_api_root + class KvKConfig(SingletonModel): api_root = models.URLField( verbose_name=_("API root"), max_length=128, - help_text=_("The root of the API (e.g. https://api.kvk.nl/api/v1)"), + validators=[validate_api_root], + help_text=_( + "The root of the API without version number and endpoint " + "(e.g. https://api.kvk.nl/api/ or https://api.kvk.nl/test/api)." + ), ) api_key = models.CharField( verbose_name=_("API key"), diff --git a/src/open_inwoner/kvk/tests/mocks.py b/src/open_inwoner/kvk/tests/mocks.py index 2af1e23585..abad4406bf 100644 --- a/src/open_inwoner/kvk/tests/mocks.py +++ b/src/open_inwoner/kvk/tests/mocks.py @@ -7,78 +7,131 @@ simple = { "pagina": 1, - "aantal": 1, + "resultatenPerPagina": 10, "totaal": 1, "resultaten": [ { - "kvkNummer": "68750110", - "handelsnaam": "Test BV Donald", + "kvkNummer": "55505201", + "naam": "Company Newtex", + "adres": { + "binnenlandsAdres": { + "type": "bezoekadres", + "straatnaam": "Japiksestraat", + "plaats": "Eindhoven", + } + }, "type": "rechtspersoon", - "links": [ - { - "rel": "basisprofiel", - "href": "https://api.kvk.nl/test/api/v1/basisprofielen/68750110", + "_links": { + "basisprofiel": { + "href": "https://api.kvk.nl/test/api/v1/basisprofielen/55505201" } - ], + }, } ], + "_links": { + "self": { + "href": "https://api.kvk.nl/test/api/v2/zoeken?kvknummer=55505201&pagina=1&resultatenperpagina=10" + } + }, } -multiple = { +hoofdvestiging = { "pagina": 1, - "aantal": 10, + "resultatenPerPagina": 10, + "totaal": 1, + "resultaten": [ + { + "kvkNummer": "68750110", + "vestigingsnummer": "000037178598", + "naam": "Test BV Donald", + "adres": { + "binnenlandsAdres": { + "type": "bezoekadres", + "straatnaam": "Hizzaarderlaan", + "plaats": "Lollum", + } + }, + "type": "hoofdvestiging", + "_links": { + "basisprofiel": { + "href": "https://api.kvk.nl/test/api/v1/basisprofielen/68750110" + }, + "vestigingsprofiel": { + "href": "https://api.kvk.nl/test/api/v1/vestigingsprofielen/000037178598" + }, + }, + } + ], + "_links": { + "self": { + "href": "https://api.kvk.nl/test/api/v2/zoeken?kvknummer=68750110&pagina=1&resultatenperpagina=10&type=hoofdvestiging" + } + }, +} + +multiple_branches = { + "pagina": 1, + "resultatenPerPagina": 10, "totaal": 3, "resultaten": [ { "kvkNummer": "68750110", - "handelsnaam": "Test BV Donald", + "naam": "Test BV Donald", "type": "rechtspersoon", - "links": [ - { - "rel": "basisprofiel", - "href": "https://api.kvk.nl/test/api/v1/basisprofielen/68750110", + "_links": { + "basisprofiel": { + "href": "https://api.kvk.nl/test/api/v1/basisprofielen/68750110" } - ], + }, }, { "kvkNummer": "68750110", - "vestigingsnummer": "000037178601", - "handelsnaam": "Test BV Donald Nevenvestiging", - "adresType": "bezoekadres", - "straatnaam": "Brinkerinckbaan", - "plaats": "Diepenveen", - "type": "nevenvestiging", - "links": [ - { - "rel": "basisprofiel", - "href": "https://api.kvk.nl/test/api/v1/basisprofielen/68750110", + "vestigingsnummer": "000037178598", + "naam": "Test BV Donald", + "adres": { + "binnenlandsAdres": { + "type": "bezoekadres", + "straatnaam": "Hizzaarderlaan", + "plaats": "Lollum", + } + }, + "type": "hoofdvestiging", + "_links": { + "basisprofiel": { + "href": "https://api.kvk.nl/test/api/v1/basisprofielen/68750110" }, - { - "rel": "vestigingsprofiel", - "href": "https://api.kvk.nl/test/api/v1/vestigingsprofielen/000037178601", + "vestigingsprofiel": { + "href": "https://api.kvk.nl/test/api/v1/vestigingsprofielen/000037178598" }, - ], + }, }, { "kvkNummer": "68750110", - "vestigingsnummer": "000037178598", - "handelsnaam": "Test BV Donald", - "adresType": "bezoekadres", - "straatnaam": "Hizzaarderlaan", - "plaats": "Lollum", - "type": "hoofdvestiging", - "links": [ - { - "rel": "basisprofiel", - "href": "https://api.kvk.nl/test/api/v1/basisprofielen/68750110", + "vestigingsnummer": "000037178601", + "naam": "Test BV Donald Nevenvestiging", + "adres": { + "binnenlandsAdres": { + "type": "bezoekadres", + "straatnaam": "Brinkerinckbaan", + "plaats": "Diepenveen", + } + }, + "type": "nevenvestiging", + "_links": { + "basisprofiel": { + "href": "https://api.kvk.nl/test/api/v1/basisprofielen/68750110" }, - { - "rel": "vestigingsprofiel", - "href": "https://api.kvk.nl/test/api/v1/vestigingsprofielen/000037178598", + "vestigingsprofiel": { + "href": "https://api.kvk.nl/test/api/v1/vestigingsprofielen/000037178601" }, - ], + }, }, ], + "_links": { + "self": { + "href": "https://api.kvk.nl/test/api/v2/zoeken?kvknummer=68750110&pagina=1&resultatenperpagina=10" + } + }, } basisprofiel_detail = { diff --git a/src/open_inwoner/kvk/tests/test_api.py b/src/open_inwoner/kvk/tests/test_api.py index 072521458b..0c6281e9fd 100644 --- a/src/open_inwoner/kvk/tests/test_api.py +++ b/src/open_inwoner/kvk/tests/test_api.py @@ -11,33 +11,55 @@ from .factories import CLIENT_CERT, CLIENT_CERT_PAIR, SERVER_CERT +@patch("open_inwoner.kvk.client.requests.get") class KvKAPITest(TestCase): - @classmethod - def setUpTestData(cls): - config = KvKConfig( - api_root="https://api.kvk.nl/test/api/v1", + def setUp(self): + self.config = KvKConfig( + api_root="https://api.kvk.nl/test/api/", api_key="12345", client_certificate=CLIENT_CERT, server_certificate=SERVER_CERT, ) - cls.kvk_client = KvKClient(config) + self.kvk_client = KvKClient(self.config) + + def test_search_endpoint(self, m): + """ + Assert that the "Zoeken" API url is constructed properly from the API root: + - trailing slashes are ignored + - correct API version number is inserted + - endpoint is appended + """ + endpoint1 = self.kvk_client.search_endpoint - def setUp(self): - patched_requests = patch("open_inwoner.kvk.client.requests.get") - self.mocked_requests = patched_requests.start() - self.addCleanup(patch.stopall) + # second client for contrast: same root but without '/' + kvk_client2 = KvKClient(self.config) + kvk_client2.config.api_root = "https://api.kvk.nl/test/api" - def test_search_endpoint(self): - self.kvk_client.config.api_root = "https://api.kvk.nl/test/api/v1" - endpoint1 = self.kvk_client.search_endpoint + endpoint2 = kvk_client2.search_endpoint + + self.assertEqual(endpoint1, "https://api.kvk.nl/test/api/v2/zoeken") + self.assertEqual(endpoint1, endpoint2) - self.kvk_client.config.api_root = "https://api.kvk.nl/test/api/v1/" - endpoint2 = self.kvk_client.search_endpoint + def test_basisprofielen_endpoint(self, m): + """ + Assert that the "Basisprofielen" API url is constructed properly from the API root: + - trailing slashes are ignored + - correct API version number is inserted + - endpoint is appended + """ + endpoint1 = self.kvk_client.basisprofielen_endpoint + # second client for contrast: same root but without '/' + kvk_client2 = KvKClient(self.config) + kvk_client2.config.api_root = "https://api.kvk.nl/test/api" + + endpoint2 = kvk_client2.basisprofielen_endpoint + + self.assertEqual(endpoint1, "https://api.kvk.nl/test/api/v1/basisprofielen") self.assertEqual(endpoint1, endpoint2) - def test_generic_search_by_kvk(self): - self.mocked_requests.return_value.json.return_value = mocks.simple + def test_generic_search_by_kvk(self, m): + m.return_value.json.return_value = mocks.simple company = self.kvk_client.search(kvk="68750110") @@ -45,26 +67,38 @@ def test_generic_search_by_kvk(self): company, { "pagina": 1, - "aantal": 1, + "resultatenPerPagina": 10, "totaal": 1, "resultaten": [ { - "kvkNummer": "68750110", - "handelsnaam": "Test BV Donald", + "kvkNummer": "55505201", + "naam": "Company Newtex", + "adres": { + "binnenlandsAdres": { + "type": "bezoekadres", + "straatnaam": "Japiksestraat", + "plaats": "Eindhoven", + } + }, "type": "rechtspersoon", - "links": [ - { - "rel": "basisprofiel", - "href": "https://api.kvk.nl/test/api/v1/basisprofielen/68750110", + "_links": { + "basisprofiel": { + "href": "https://api.kvk.nl/test/api/v1/basisprofielen/55505201" } - ], + }, } ], + "_links": { + "self": { + "href": "https://api.kvk.nl/test/api/v2/zoeken?kvknummer=" + "55505201&pagina=1&resultatenperpagina=10" + } + }, }, ) - def test_search_headquarters(self): - self.mocked_requests.return_value.json.return_value = mocks.multiple + def test_search_headquarters(self, m): + m.return_value.json.return_value = mocks.hoofdvestiging headquarters = self.kvk_client.get_company_headquarters(kvk="68750110") self.assertEqual( @@ -72,26 +106,28 @@ def test_search_headquarters(self): { "kvkNummer": "68750110", "vestigingsnummer": "000037178598", - "handelsnaam": "Test BV Donald", - "adresType": "bezoekadres", - "straatnaam": "Hizzaarderlaan", - "plaats": "Lollum", + "naam": "Test BV Donald", + "adres": { + "binnenlandsAdres": { + "type": "bezoekadres", + "straatnaam": "Hizzaarderlaan", + "plaats": "Lollum", + } + }, "type": "hoofdvestiging", - "links": [ - { - "rel": "basisprofiel", - "href": "https://api.kvk.nl/test/api/v1/basisprofielen/68750110", + "_links": { + "basisprofiel": { + "href": "https://api.kvk.nl/test/api/v1/basisprofielen/68750110" }, - { - "rel": "vestigingsprofiel", - "href": "https://api.kvk.nl/test/api/v1/vestigingsprofielen/000037178598", + "vestigingsprofiel": { + "href": "https://api.kvk.nl/test/api/v1/vestigingsprofielen/000037178598" }, - ], + }, }, ) - def test_search_all_branches(self): - self.mocked_requests.return_value.json.return_value = mocks.multiple + def test_search_all_branches(self, m): + m.return_value.json.return_value = mocks.multiple_branches branches = self.kvk_client.get_all_company_branches(kvk="68750110") @@ -101,45 +137,51 @@ def test_search_all_branches(self): { "kvkNummer": "68750110", "vestigingsnummer": "000037178598", - "handelsnaam": "Test BV Donald", - "adresType": "bezoekadres", - "straatnaam": "Hizzaarderlaan", - "plaats": "Lollum", + "naam": "Test BV Donald", + "adres": { + "binnenlandsAdres": { + "type": "bezoekadres", + "straatnaam": "Hizzaarderlaan", + "plaats": "Lollum", + } + }, "type": "hoofdvestiging", - "links": [ - { - "rel": "basisprofiel", - "href": "https://api.kvk.nl/test/api/v1/basisprofielen/68750110", + "_links": { + "basisprofiel": { + "href": "https://api.kvk.nl/test/api/v1/basisprofielen/68750110" }, - { - "rel": "vestigingsprofiel", - "href": "https://api.kvk.nl/test/api/v1/vestigingsprofielen/000037178598", + "vestigingsprofiel": { + "href": "https://api.kvk.nl/test/api/v1/vestigingsprofielen/000037178598" }, - ], + }, }, { "kvkNummer": "68750110", "vestigingsnummer": "000037178601", - "handelsnaam": "Test BV Donald Nevenvestiging", - "adresType": "bezoekadres", - "straatnaam": "Brinkerinckbaan", - "plaats": "Diepenveen", + "naam": "Test BV Donald Nevenvestiging", + "adres": { + "binnenlandsAdres": { + "type": "bezoekadres", + "straatnaam": "Brinkerinckbaan", + "plaats": "Diepenveen", + } + }, "type": "nevenvestiging", - "links": [ - { - "rel": "basisprofiel", - "href": "https://api.kvk.nl/test/api/v1/basisprofielen/68750110", + "_links": { + "basisprofiel": { + "href": "https://api.kvk.nl/test/api/v1/basisprofielen/68750110" }, - { - "rel": "vestigingsprofiel", - "href": "https://api.kvk.nl/test/api/v1/vestigingsprofielen/000037178601", + "vestigingsprofiel": { + "href": "https://api.kvk.nl/test/api/v1/vestigingsprofielen/000037178601" }, - ], + }, }, ], ) - def test_no_search_without_config(self): + def test_no_search_without_config(self, m): + m.return_value.json.return_value = mocks.multiple_branches + config = None kvk_client = KvKClient(config) @@ -147,9 +189,11 @@ def test_no_search_without_config(self): self.assertEqual(company, {}) - def test_no_search_with_empty_api_root(self): + def test_no_search_with_empty_api_root(self, m): """Sentry 343407""" + m.return_value.json.return_value = mocks.multiple_branches + config = KvKConfig( api_root="", api_key="12345", @@ -164,20 +208,18 @@ def test_no_search_with_empty_api_root(self): class KvKRequestsInterfaceTest(TestCase): - @classmethod - def setUpTestData(cls): + def setUp(self): + patched_requests = patch("open_inwoner.kvk.client.requests.get") + self.mocked_requests = patched_requests.start() + self.addCleanup(patch.stopall) + config = KvKConfig( - api_root="https://api.kvk.nl/test/api/v1", + api_root="https://api.kvk.nl/test/api/v2", api_key="12345", client_certificate=CLIENT_CERT, server_certificate=SERVER_CERT, ) - cls.kvk_client = KvKClient(config) - - def setUp(self): - patched_requests = patch("open_inwoner.kvk.client.requests.get") - self.mocked_requests = patched_requests.start() - self.addCleanup(patch.stopall) + self.kvk_client = KvKClient(config) def test_kvk_client_with_certs(self): self.kvk_client.get_company_headquarters(kvk="69599084") @@ -191,7 +233,7 @@ def test_kvk_client_with_certs(self): def test_kvk_client_with_key_pair(self): config = KvKConfig( - api_root="https://api.kvk.nl/test/api/v1", + api_root="https://api.kvk.nl/test/api/v2", api_key="12345", client_certificate=CLIENT_CERT_PAIR, server_certificate=SERVER_CERT, @@ -212,7 +254,7 @@ def test_kvk_client_with_key_pair(self): def test_kvk_client_no_certs(self): config = KvKConfig( - api_root="https://api.kvk.nl/test/api/v1", + api_root="https://api.kvk.nl/test/api/v2", api_key="12345", ) kvk_client = KvKClient(config) diff --git a/src/open_inwoner/kvk/tests/test_migrations.py b/src/open_inwoner/kvk/tests/test_migrations.py new file mode 100644 index 0000000000..f1c3aa45fc --- /dev/null +++ b/src/open_inwoner/kvk/tests/test_migrations.py @@ -0,0 +1,21 @@ +from open_inwoner.utils.tests.test_migrations import TestMigrations + + +class APIRootMigrationTest(TestMigrations): + migrate_from = "0002_alter_kvkconfig_api_root" + migrate_to = "0003_api_root" + app = "kvk" + + def setUpBeforeMigration(self, apps): + KvKConfig = apps.get_model("kvk", "KvKConfig") + + KvKConfig.objects.create( + api_root="https://kvk.example.nl/api/v1/", api_key="dummy" + ) + + def test_migrate_api_root(self): + KvKConfig = self.apps.get_model("kvk", "KvKConfig") + + config = KvKConfig.objects.first() + + self.assertEqual(config.api_root, "https://kvk.example.nl/api") diff --git a/src/open_inwoner/kvk/tests/test_validators.py b/src/open_inwoner/kvk/tests/test_validators.py new file mode 100644 index 0000000000..5451e4e5bd --- /dev/null +++ b/src/open_inwoner/kvk/tests/test_validators.py @@ -0,0 +1,36 @@ +from django.core.exceptions import ValidationError +from django.test import TestCase +from django.utils.translation import gettext as _ + +from ..validators import validate_api_root + + +class KvKAPIRootValidationTest(TestCase): + @classmethod + def setUpTestData(cls): + cls.error_msg = _( + "The API root is incorrect. Please double-check that " + "you didn't include the version number or endpoint." + ) + + def test_kvk_api_root_invalid(self): + test_cases = ( + "https://api.kvk.nl/api/v1", + "https://api.kvk.nl/api/v1/test", + "https://api.kvk.nl/api/123", + ) + for i, test_string in enumerate(test_cases): + with self.subTest(i=i): + with self.assertRaisesMessage(ValidationError, self.error_msg): + validate_api_root(test_string) + + def test_kvk_api_root_valid(self): + test_cases = ( + "https://api.kvk.nl/api", + "https://api.kvk.nl/api/", + "https://api.kvk.nl/test/api", + "https://api.kvk.nl/test/api/", + ) + for i, test_string in enumerate(test_cases): + with self.subTest(i=i): + validate_api_root(test_string) diff --git a/src/open_inwoner/kvk/tests/test_views.py b/src/open_inwoner/kvk/tests/test_views.py index 7b274130e2..4198c8c3b9 100644 --- a/src/open_inwoner/kvk/tests/test_views.py +++ b/src/open_inwoner/kvk/tests/test_views.py @@ -190,12 +190,12 @@ def test_get_branches_page_one_branch_found_sets_branch_check_done( def test_get_branches_page(self, mock_solo, mock_kvk): mock_kvk.return_value = [ { - "handelsnaam": "Makers and Shakers", + "naam": "Makers and Shakers", "kvkNummer": "12345678", "vestigingsnummer": "1234", }, { - "handelsnaam": "Makers and Shakers", + "naam": "Makers and Shakers", "kvkNummer": "12345678", "vestigingsnummer": "5678", }, @@ -221,3 +221,7 @@ def test_get_branches_page(self, mock_solo, mock_kvk): self.assertEqual(branch_inputs[0], doc.find("[id='branch-']")[0]) self.assertEqual(branch_inputs[1], doc.find("[id='branch-1234']")[0]) self.assertEqual(branch_inputs[2], doc.find("[id='branch-5678']")[0]) + + # chack that company name is displayed for every branch + company_name_displays = doc("p:Contains('Makers and Shakers')") + self.assertEqual(len(company_name_displays), 3) diff --git a/src/open_inwoner/kvk/validators.py b/src/open_inwoner/kvk/validators.py new file mode 100644 index 0000000000..3a3cf3e4b9 --- /dev/null +++ b/src/open_inwoner/kvk/validators.py @@ -0,0 +1,16 @@ +import re + +from django.core.exceptions import ValidationError +from django.utils.translation import gettext_lazy as _ + +regexp = re.compile("/api/[0-9a-z]") + + +def validate_api_root(value): + if regexp.search(value, re.IGNORECASE): + raise ValidationError( + _( + "The API root is incorrect. Please double-check that " + "you didn't include the version number or endpoint." + ) + ) diff --git a/src/open_inwoner/kvk/views.py b/src/open_inwoner/kvk/views.py index 68611befa5..67a10b9489 100644 --- a/src/open_inwoner/kvk/views.py +++ b/src/open_inwoner/kvk/views.py @@ -40,9 +40,7 @@ def get_context_data(self, **kwargs): # create pseudo-branch representing the company as a whole master_branch = { "vestigingsnummer": "", - "handelsnaam": company_branches[0].get("handelsnaam", "") - if company_branches - else "", + "naam": company_branches[0].get("naam", "") if company_branches else "", } company_branches.insert(0, master_branch) diff --git a/src/open_inwoner/templates/pages/kvk/branches.html b/src/open_inwoner/templates/pages/kvk/branches.html index 722f722e4c..899f7e45f6 100644 --- a/src/open_inwoner/templates/pages/kvk/branches.html +++ b/src/open_inwoner/templates/pages/kvk/branches.html @@ -14,7 +14,7 @@ {% render_card direction='horizontal' %} {% with company_id=branch.vestigingsnummer %}