Skip to content

Commit

Permalink
Merge pull request #877 from maykinmedia/fix/1890-kvk-not-configured
Browse files Browse the repository at this point in the history
[#1890] Require API root for KvK config
  • Loading branch information
stevenbal authored Dec 4, 2023
2 parents 97ca46d + f972109 commit fb7829f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/open_inwoner/contrib/kvk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ def _build_request_kwargs(self) -> dict:

return request_kwargs

def _request(self, endpoint: str, params: dict) -> list:
def _request(self, endpoint: str, params: dict) -> dict:
if not self.config or not self.config.api_root:
return {}

url = self._build_url(endpoint, params=params)
request_kwargs = self._build_request_kwargs()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.20 on 2023-12-04 12:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("kvk", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="kvkconfig",
name="api_root",
field=models.URLField(
help_text="The root of the API (e.g. https://api.kvk.nl/api/v1)",
max_length=128,
verbose_name="API root",
),
),
]
1 change: 0 additions & 1 deletion src/open_inwoner/contrib/kvk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class KvKConfig(SingletonModel):
api_root = models.URLField(
verbose_name=_("API root"),
max_length=128,
blank=True,
help_text=_("The root of the API (e.g. https://api.kvk.nl/api/v1)"),
)
api_key = models.CharField(
Expand Down
23 changes: 23 additions & 0 deletions src/open_inwoner/contrib/kvk/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,29 @@ def test_search_by_kvk_extra_params(self):
},
)

def test_no_search_without_config(self):
config = None
kvk_client = KvKClient(config)

company = kvk_client.search(kvk="69599084")

self.assertEqual(company, {})

def test_no_search_with_empty_api_root(self):
"""Sentry 343407"""

config = KvKConfig(
api_root="",
api_key="12345",
client_certificate=CLIENT_CERT,
server_certificate=SERVER_CERT,
)
kvk_client = KvKClient(config)

company = kvk_client.search(kvk="69599084")

self.assertEqual(company, {})

#
# requests interface
#
Expand Down

0 comments on commit fb7829f

Please sign in to comment.