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

[#2069] Upgrade KvK Zoeken API to v2 #1016

Merged
merged 4 commits into from
Feb 20, 2024
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
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
Comment on lines +65 to +67
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably from another PR? Doesn't actually change anything though, so it's fine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double-checked: I branched off upgrade/django-admin-index instead of develop when starting on this. The PR has been merged though.

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 @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -974,6 +976,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 @@ -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",
},
]

Expand Down
6 changes: 3 additions & 3 deletions src/open_inwoner/kvk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
27 changes: 27 additions & 0 deletions src/open_inwoner/kvk/migrations/0003_api_root.py
Original file line number Diff line number Diff line change
@@ -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
),
]
24 changes: 24 additions & 0 deletions src/open_inwoner/kvk/migrations/0004_alter_kvkconfig_api_root.py
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
8 changes: 7 additions & 1 deletion src/open_inwoner/kvk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
141 changes: 97 additions & 44 deletions src/open_inwoner/kvk/tests/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
pi-sigma marked this conversation as resolved.
Show resolved Hide resolved
"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 = {
Expand Down
Loading
Loading