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

Referentielijsten API #125

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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
Empty file.
36 changes: 36 additions & 0 deletions src/openklant/components/referentielijsten/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import datetime

from django.contrib import admin

from . import models


@admin.register(models.ExternRegister)
class ExternRegisterAdmin(admin.ModelAdmin):
list_display = ["code", "naam"]


@admin.register(models.Land)
class LandAdmin(admin.ModelAdmin):
list_display = ["landcode", "landnaam", "indicatie_actief"]

@admin.display(boolean=True)
def indicatie_actief(self, land: models.Land) -> bool:
return land.ingangsdatum_land <= datetime.date.today() < land.einddatum_land


class CommonAdmin(admin.ModelAdmin):
list_display = ["code", "naam", "indicatie_actief"]
list_filter = ["indicatie_actief"]


admin.site.register(
[
models.Kanaal,
models.SoortDigitaalAdres,
models.SoortObject,
models.SoortObjectid,
models.Taal,
],
CommonAdmin,
)
Empty file.
13 changes: 13 additions & 0 deletions src/openklant/components/referentielijsten/api/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.conf import settings

description = """
Een API om de referentielijsten in het domein klantinteracties te raadplegen en beheren.
""".strip()

# Spectacular settings overrides
custom_settings = {
"TITLE": "Klantinteracties Referentielijsten",
"VERSION": settings.REFERENTIELIJSTEN_API_VERSION,
"DESCRIPTION": description,
"SCHEMA_PATH_PREFIX_TRIM": True,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from .extern_register import ExternRegisterSerializer
from .kanaal import KanaalSerializer
from .land import LandSerializer
from .soort_digitaal_adres import SoortDigitaalAdresSerializer
from .soort_object import SoortObjectSerializer
from .soort_objectid import SoortObjectidSerializer
from .taal import TaalSerializer

__all__ = [
"ExternRegisterSerializer",
"KanaalSerializer",
"LandSerializer",
"SoortDigitaalAdresSerializer",
"SoortObjectSerializer",
"SoortObjectidSerializer",
"TaalSerializer",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework import serializers

from ...models import ExternRegister


class ExternRegisterSerializer(serializers.ModelSerializer):
class Meta:
model = ExternRegister
fields = [
"code",
"locatie",
"naam",
]

__doc__ = Meta.model.__doc__
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework import serializers

from ...models import Kanaal


class KanaalSerializer(serializers.ModelSerializer):
class Meta:
model = Kanaal
fields = [
"code",
"indicatie_actief",
"naam",
]

__doc__ = Meta.model.__doc__
16 changes: 16 additions & 0 deletions src/openklant/components/referentielijsten/api/serializers/land.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from rest_framework import serializers

from ...models import Land


class LandSerializer(serializers.ModelSerializer):
class Meta:
model = Land
fields = [
"landcode",
"landnaam",
"ingangsdatum_land",
"einddatum_land",
]

__doc__ = Meta.model.__doc__
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework import serializers

from ...models import SoortDigitaalAdres


class SoortDigitaalAdresSerializer(serializers.ModelSerializer):
class Meta:
model = SoortDigitaalAdres
fields = [
"code",
"indicatie_actief",
"naam",
]

__doc__ = Meta.model.__doc__
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework import serializers

from ...models import SoortObject


class SoortObjectSerializer(serializers.ModelSerializer):
class Meta:
model = SoortObject
fields = [
"code",
"indicatie_actief",
"naam",
]

__doc__ = Meta.model.__doc__
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework import serializers

from ...models import SoortObjectid


class SoortObjectidSerializer(serializers.ModelSerializer):
class Meta:
model = SoortObjectid
fields = [
"code",
"indicatie_actief",
"naam",
]

__doc__ = Meta.model.__doc__
15 changes: 15 additions & 0 deletions src/openklant/components/referentielijsten/api/serializers/taal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework import serializers

from ...models import Taal


class TaalSerializer(serializers.ModelSerializer):
class Meta:
model = Taal
fields = [
"code",
"indicatie_actief",
"naam",
]

__doc__ = Meta.model.__doc__
Empty file.
73 changes: 73 additions & 0 deletions src/openklant/components/referentielijsten/api/tests/factories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import datetime

import factory
import factory.random

from ... import models


class ExternRegisterFactory(factory.django.DjangoModelFactory):
code = factory.Sequence(lambda n: f"code-{n}")
locatie = factory.Faker("name")
naam = factory.Faker("name")

class Meta:
model = models.ExternRegister


class KanaalFactory(factory.django.DjangoModelFactory):
code = factory.Sequence(lambda n: f"code-{n}")
indicatie_actief = factory.Faker("pybool")
naam = factory.Faker("name")

class Meta:
model = models.Kanaal


class LandFactory(factory.django.DjangoModelFactory):
landcode = factory.Sequence(lambda n: f"landcode-{n}")
landnaam = factory.Faker("country")
ingangsdatum_land = factory.Faker("date_object")
einddatum_land = factory.LazyAttribute(
lambda land: land.ingangsdatum_land
+ datetime.timedelta(factory.random.randgen.randint(0, 2e6))
)

class Meta:
model = models.Land


class SoortDigitaalAdresFactory(factory.django.DjangoModelFactory):
code = factory.Sequence(lambda n: f"code-{n}")
indicatie_actief = factory.Faker("pybool")
naam = factory.Faker("name")

class Meta:
model = models.SoortDigitaalAdres


class SoortObjectFactory(factory.django.DjangoModelFactory):
code = factory.Sequence(lambda n: f"code-{n}")
indicatie_actief = factory.Faker("pybool")
naam = factory.Faker("name")

class Meta:
model = models.SoortObject


class SoortObjectidFactory(factory.django.DjangoModelFactory):
code = factory.Sequence(lambda n: f"code-{n}")
indicatie_actief = factory.Faker("pybool")
naam = factory.Faker("name")

class Meta:
model = models.SoortObjectid


class TaalFactory(factory.django.DjangoModelFactory):
code = factory.Sequence(lambda n: f"code-{n}")
indicatie_actief = factory.Faker("pybool")
naam = factory.Faker("language_name")

class Meta:
model = models.Taal
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
from rest_framework import status
from rest_framework.test import APITestCase
from vng_api_common.tests import reverse

from . import factories


class ExterneRegistersTests(APITestCase):
def test_getexterneregisters(self):
url = reverse("referentielijsten:externregister-list")
factories.ExternRegisterFactory.create_batch(1000)

response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
response_data = response.json()
self.assertEqual(len(response_data), 1000)

def test_postregister(self):
url = reverse("referentielijsten:externregister-list")
data = {
"code": "XKX",
"locatie": "Kosovo",
"naam": "2013-04-19",
}

response = self.client.post(url, data)

self.assertEqual(response.status_code, status.HTTP_201_CREATED)

response_data = response.json()
self.assertEqual(response_data["code"], "XKX")
self.assertEqual(response_data["locatie"], "Kosovo")
self.assertEqual(response_data["naam"], "2013-04-19")

def test_delregister(self):
extern_register, other = factories.ExternRegisterFactory.create_batch(2)
url = reverse(
"referentielijsten:externregister-detail",
kwargs={"code": extern_register.code},
)

response = self.client.delete(url)
self.assertIn(
response.status_code,
[status.HTTP_200_OK, status.HTTP_204_NO_CONTENT],
)

# assert it's gone
get_response = self.client.get(url)
self.assertEqual(get_response.status_code, status.HTTP_404_NOT_FOUND)

# assert other still exists
other_url = reverse(
"referentielijsten:externregister-detail",
kwargs={"code": other.code},
)
other_response = self.client.get(other_url)
self.assertEqual(other_response.status_code, status.HTTP_200_OK)

def test_getregister(self):
factories.ExternRegisterFactory.create(
code="XKX",
locatie="Kosovo",
naam="2013-04-19",
)

url = reverse("referentielijsten:externregister-detail", kwargs={"code": "XKX"})

response = self.client.get(url)

self.assertEqual(response.status_code, status.HTTP_200_OK)
response_data = response.json()
self.assertEqual(response_data["code"], "XKX")
self.assertEqual(response_data["locatie"], "Kosovo")
self.assertEqual(response_data["naam"], "2013-04-19")

def test_putregister(self):
factories.ExternRegisterFactory.create(
code="BFA",
locatie="Boven-Volta",
naam="1966-01-03",
)

data = {
"code": "BFA",
"locatie": "Burkina Faso",
"naam": "2014-11-03",
}

url = reverse("referentielijsten:externregister-detail", kwargs={"code": "BFA"})

response = self.client.put(url, data)

self.assertEqual(response.status_code, status.HTTP_200_OK)
response_data = response.json()

self.assertEqual(response_data["code"], "BFA")
self.assertEqual(response_data["locatie"], "Burkina Faso")
self.assertEqual(response_data["naam"], "2014-11-03")
Loading