Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1890] Require API root for KvK config #877

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading