Skip to content

Commit

Permalink
[#2096] Change 'handelsnaam' to 'naam' and refactor api root validation
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Feb 16, 2024
1 parent 753f578 commit ae0d71a
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 29 deletions.
6 changes: 5 additions & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -341,6 +343,7 @@ lockfile==0.12.2
lxml==4.9.1
# via
# django-digid-eherkenning
# mail-editor
# maykin-python3-saml
# svglib
# xmlsec
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,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
Expand Down Expand Up @@ -598,6 +599,7 @@ lxml==4.9.1
# -c requirements/base.txt
# -r requirements/base.txt
# django-digid-eherkenning
# mail-editor
# maykin-python3-saml
# pyquery
# svglib
Expand Down Expand Up @@ -815,6 +817,7 @@ requests==2.31.0
# django-open-forms-client
# django-rosetta
# gemma-zds-client
# mail-editor
# maykin-python3-saml
# messagebird
# mozilla-django-oidc
Expand Down
3 changes: 3 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,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
Expand Down Expand Up @@ -696,6 +697,7 @@ lxml==4.9.1
# -c requirements/ci.txt
# -r requirements/ci.txt
# django-digid-eherkenning
# mail-editor
# maykin-python3-saml
# pyquery
# svglib
Expand Down Expand Up @@ -960,6 +962,7 @@ requests==2.31.0
# django-rosetta
# gemma-zds-client
# locust
# mail-editor
# maykin-python3-saml
# messagebird
# mozilla-django-oidc
Expand Down
4 changes: 2 additions & 2 deletions src/open_inwoner/accounts/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,12 +1081,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",
},
]

Expand Down
19 changes: 4 additions & 15 deletions src/open_inwoner/kvk/tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class KvKAPIRootValidationTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.error_msg = _(
"The API root is incorrect. Please double-check that the host is correct "
"and you didn't include the version number or endpoint."
"The API root is incorrect. Please double-check that "
"you didn't include the version number or endpoint."
)

def test_invalid_because_version_number_or_endpoint_included(self):
def test_kvk_api_root_invalid(self):
test_cases = (
"https://api.kvk.nl/api/v1",
"https://api.kvk.nl/api/v1/test",
Expand All @@ -24,18 +24,7 @@ def test_invalid_because_version_number_or_endpoint_included(self):
with self.assertRaisesMessage(ValidationError, self.error_msg):
validate_api_root(test_string)

def test_invalid_kvk_host(self):
test_cases = (
"https://kvk.api.nl/api",
"https://apii.kvk.nl/test/api",
"http://api.kvk.nl/",
)
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_valid_kvk_api_root(self):
def test_kvk_api_root_valid(self):
test_cases = (
"https://api.kvk.nl/api",
"https://api.kvk.nl/api/",
Expand Down
14 changes: 4 additions & 10 deletions src/open_inwoner/kvk/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,14 @@
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _

# There are only 4 possibilities, let's enumerate them
regexes = (
re.compile(r"^https://api.kvk.nl/api$"),
re.compile(r"^https://api.kvk.nl/api/$"),
re.compile(r"^https://api.kvk.nl/test/api$"),
re.compile(r"^https://api.kvk.nl/test/api/$"),
)
regexp = re.compile("/api/[0-9a-z]")


def validate_api_root(value):
if not any(regex.match(value) for regex in regexes):
if regexp.search(value, re.IGNORECASE):
raise ValidationError(
_(
"The API root is incorrect. Please double-check that the host is "
"correct and you didn't include the version number or endpoint."
"The API root is incorrect. Please double-check that "
"you didn't include the version number or endpoint."
)
)
2 changes: 1 addition & 1 deletion src/open_inwoner/templates/pages/kvk/branches.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{% render_card direction='horizontal' %}
{% with company_id=branch.vestigingsnummer %}
<label class="left" for="branch-{{ company_id }}">
<p>{{ branch.handelsnaam }}</p>
<p>{{ branch.naam }}</p>
{% if branch.straatnaam and branch.plaats %}
<p>{{ branch.straatnaam }}, {{ branch.plaats}}</p>
{% endif %}
Expand Down

0 comments on commit ae0d71a

Please sign in to comment.