Skip to content

Commit

Permalink
[#233] Change field type
Browse files Browse the repository at this point in the history
[#233] Fix admin

[#233] Migrations

[#233] Revert commits

[#233] Remove admin blocks

[#233] Update models and migrations

[#233] Fix tests

[#233] Fix and extend tests

[#233] Create validators

[#233] Fix validators

[#233] Fix tests

[#233] Fix migrations

[#233] Formatting

[#233] Merge

[#233] Run isort

[#233] Run black

[#233] Run flake and fix tests
  • Loading branch information
danielmursa-dev committed Nov 26, 2024
1 parent 240d965 commit d395b24
Show file tree
Hide file tree
Showing 5 changed files with 481 additions and 38 deletions.
283 changes: 246 additions & 37 deletions src/openklant/components/klantinteracties/api/tests/test_partijen.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import datetime

from django.core.exceptions import ValidationError
from django.utils.translation import gettext as _

from rest_framework import status
from vng_api_common.tests import reverse

from openklant.components.klantinteracties.models.constants import SoortPartij
from openklant.components.klantinteracties.models.constants import (
PartijIdentificatorCodeObjectType,
PartijIdentificatorCodeRegister,
PartijIdentificatorCodeSoortObjectId,
SoortPartij,
)
from openklant.components.klantinteracties.models.partijen import Partij
from openklant.components.klantinteracties.models.tests.factories.digitaal_adres import (
DigitaalAdresFactory,
Expand Down Expand Up @@ -1873,10 +1879,10 @@ def test_create_partij_indetificator(self):
"identificeerdePartij": {"uuid": str(partij.uuid)},
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": "codeObjecttype",
"codeSoortObjectId": "codeSoortObjectId",
"objectId": "objectId",
"codeRegister": "codeRegister",
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"objectId": "123456788",
"codeRegister": PartijIdentificatorCodeRegister.brp,
},
}

Expand All @@ -1889,10 +1895,10 @@ def test_create_partij_indetificator(self):
self.assertEqual(
data["partijIdentificator"],
{
"codeObjecttype": "codeObjecttype",
"codeSoortObjectId": "codeSoortObjectId",
"objectId": "objectId",
"codeRegister": "codeRegister",
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"objectId": "123456788",
"codeRegister": PartijIdentificatorCodeRegister.brp,
},
)

Expand All @@ -1901,10 +1907,10 @@ def test_update_partij_indetificator(self):
partij_identificator = PartijIdentificatorFactory.create(
partij=partij,
andere_partij_identificator="anderePartijIdentificator",
partij_identificator_code_objecttype="codeObjecttype",
partij_identificator_code_soort_object_id="codeSoortObjectId",
partij_identificator_object_id="objectId",
partij_identificator_code_register="codeRegister",
partij_identificator_code_objecttype=PartijIdentificatorCodeObjectType.natuurlijk_persoon,
partij_identificator_code_soort_object_id=PartijIdentificatorCodeSoortObjectId.bsn,
partij_identificator_object_id="123456788",
partij_identificator_code_register=PartijIdentificatorCodeRegister.brp,
)

detail_url = reverse(
Expand All @@ -1919,21 +1925,21 @@ def test_update_partij_indetificator(self):
self.assertEqual(
data["partijIdentificator"],
{
"codeObjecttype": "codeObjecttype",
"codeSoortObjectId": "codeSoortObjectId",
"objectId": "objectId",
"codeRegister": "codeRegister",
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"objectId": "123456788",
"codeRegister": PartijIdentificatorCodeRegister.brp,
},
)

data = {
"identificeerdePartij": {"uuid": str(partij2.uuid)},
"anderePartijIdentificator": "changed",
"partijIdentificator": {
"codeObjecttype": "changed",
"codeSoortObjectId": "changed",
"objectId": "changed",
"codeRegister": "changed",
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"objectId": "123456789",
"codeRegister": PartijIdentificatorCodeRegister.brp,
},
}

Expand All @@ -1946,10 +1952,10 @@ def test_update_partij_indetificator(self):
self.assertEqual(
data["partijIdentificator"],
{
"codeObjecttype": "changed",
"codeSoortObjectId": "changed",
"objectId": "changed",
"codeRegister": "changed",
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"objectId": "123456789",
"codeRegister": PartijIdentificatorCodeRegister.brp,
},
)

Expand All @@ -1958,10 +1964,10 @@ def test_partial_update_partij_indetificator(self):
partij_identificator = PartijIdentificatorFactory.create(
partij=partij,
andere_partij_identificator="anderePartijIdentificator",
partij_identificator_code_objecttype="codeObjecttype",
partij_identificator_code_soort_object_id="codeSoortObjectId",
partij_identificator_object_id="objectId",
partij_identificator_code_register="codeRegister",
partij_identificator_code_objecttype=PartijIdentificatorCodeObjectType.natuurlijk_persoon,
partij_identificator_code_soort_object_id=PartijIdentificatorCodeSoortObjectId.bsn,
partij_identificator_object_id="123456788",
partij_identificator_code_register=PartijIdentificatorCodeRegister.brp,
)

detail_url = reverse(
Expand All @@ -1976,10 +1982,10 @@ def test_partial_update_partij_indetificator(self):
self.assertEqual(
data["partijIdentificator"],
{
"codeObjecttype": "codeObjecttype",
"codeSoortObjectId": "codeSoortObjectId",
"objectId": "objectId",
"codeRegister": "codeRegister",
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"objectId": "123456788",
"codeRegister": PartijIdentificatorCodeRegister.brp,
},
)

Expand All @@ -1996,10 +2002,10 @@ def test_partial_update_partij_indetificator(self):
self.assertEqual(
data["partijIdentificator"],
{
"codeObjecttype": "codeObjecttype",
"codeSoortObjectId": "codeSoortObjectId",
"objectId": "objectId",
"codeRegister": "codeRegister",
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"objectId": "123456788",
"codeRegister": PartijIdentificatorCodeRegister.brp,
},
)

Expand All @@ -2017,6 +2023,209 @@ def test_destroy_partij_identificator(self):
data = response.json()
self.assertEqual(data["count"], 0)

def test_invalid_choice_partij_identificator_code_register(self):
url = reverse("klantinteracties:partijidentificator-list")
partij = PartijFactory.create()
data = {
"identificeerdePartij": {"uuid": str(partij.uuid)},
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"objectId": 12,
"codeRegister": "test",
},
}
response = self.client.post(url, data)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data["code"], "invalid")
self.assertEqual(response.data["title"], "Invalid input.")
self.assertEqual(
response.data["invalid_params"][0]["name"],
"partijIdentificator.codeRegister",
)
self.assertEqual(response.data["invalid_params"][0]["code"], "invalid_choice")
self.assertEqual(
response.data["invalid_params"][0]["reason"],
'"test" is een ongeldige keuze.',
)

def test_invalid_choice_partij_identificator_code_objecttype(self):
url = reverse("klantinteracties:partijidentificator-list")
partij = PartijFactory.create()
data = {
"identificeerdePartij": {"uuid": str(partij.uuid)},
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": "test",
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"objectId": 12,
"codeRegister": PartijIdentificatorCodeRegister.brp,
},
}
response = self.client.post(url, data)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data["code"], "invalid")
self.assertEqual(response.data["title"], "Invalid input.")
self.assertEqual(
response.data["invalid_params"][0]["name"],
"partijIdentificator.codeObjecttype",
)
self.assertEqual(response.data["invalid_params"][0]["code"], "invalid_choice")
self.assertEqual(
response.data["invalid_params"][0]["reason"],
'"test" is een ongeldige keuze.',
)

def test_invalid_choice_partij_identificator_code_soort_object_id(self):
url = reverse("klantinteracties:partijidentificator-list")
partij = PartijFactory.create()
data = {
"identificeerdePartij": {"uuid": str(partij.uuid)},
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": "test",
"objectId": 12,
"codeRegister": PartijIdentificatorCodeRegister.brp,
},
}
response = self.client.post(url, data)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data["code"], "invalid")
self.assertEqual(response.data["title"], "Invalid input.")
self.assertEqual(
response.data["invalid_params"][0]["name"],
"partijIdentificator.codeSoortObjectId",
)
self.assertEqual(response.data["invalid_params"][0]["code"], "invalid_choice")
self.assertEqual(
response.data["invalid_params"][0]["reason"],
'"test" is een ongeldige keuze.',
)

def test_invalid_validation_partij_identificator_code_objecttype(self):
url = reverse("klantinteracties:partijidentificator-list")
partij = PartijFactory.create()
data = {
"identificeerdePartij": {"uuid": str(partij.uuid)},
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": PartijIdentificatorCodeObjectType.niet_natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"objectId": 12,
"codeRegister": PartijIdentificatorCodeRegister.brp,
},
}

with self.assertRaisesMessage(
ValidationError, "ObjectType keuzes zijn beperkt op basis van Register"
):
self.client.post(url, data)

def test_invalid_validation_partij_identificator_code_soort_object_id(self):
url = reverse("klantinteracties:partijidentificator-list")
partij = PartijFactory.create()
data = {
"identificeerdePartij": {"uuid": str(partij.uuid)},
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.kvknummer,
"objectId": 12,
"codeRegister": PartijIdentificatorCodeRegister.brp,
},
}

with self.assertRaisesMessage(
ValidationError,
"CodeSoortObjectIdValidator keuzes zijn beperkt op basis van CodeObjectType",
):
self.client.post(url, data)

def test_invalid_validation_partij_identificator_object_id(self):
url = reverse("klantinteracties:partijidentificator-list")
partij = PartijFactory.create()
data = {
"identificeerdePartij": {"uuid": str(partij.uuid)},
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"objectId": 12,
"codeRegister": PartijIdentificatorCodeRegister.brp,
},
}

with self.assertRaisesMessage(
ValidationError, "De lengte van de ObjectId moet tussen 8 en 9 liggen."
):
self.client.post(url, data)

def test_valid_validation_partij_identificator(self):
# All validations pass
url = reverse("klantinteracties:partijidentificator-list")
partij = PartijFactory.create()
data = {
"identificeerdePartij": {"uuid": str(partij.uuid)},
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"objectId": 123456789,
"codeRegister": PartijIdentificatorCodeRegister.brp,
},
}
response = self.client.post(url, data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(
response.data["partij_identificator"]["code_objecttype"],
PartijIdentificatorCodeObjectType.natuurlijk_persoon,
)
self.assertEqual(
response.data["partij_identificator"]["code_soort_object_id"],
PartijIdentificatorCodeSoortObjectId.bsn,
)
self.assertEqual(
response.data["partij_identificator"]["object_id"], "123456789"
)
self.assertEqual(
response.data["partij_identificator"]["code_register"],
PartijIdentificatorCodeRegister.brp,
)

def test_valid_overige_validation_partij_identificator(self):
# Overige no validation
url = reverse("klantinteracties:partijidentificator-list")
partij = PartijFactory.create()
data = {
"identificeerdePartij": {"uuid": str(partij.uuid)},
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.rsin,
"objectId": 123456789,
"codeRegister": PartijIdentificatorCodeRegister.overige,
},
}
response = self.client.post(url, data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(
response.data["partij_identificator"]["code_objecttype"],
PartijIdentificatorCodeObjectType.natuurlijk_persoon,
)
self.assertEqual(
response.data["partij_identificator"]["code_soort_object_id"],
PartijIdentificatorCodeSoortObjectId.rsin,
)
self.assertEqual(
response.data["partij_identificator"]["object_id"], "123456789"
)
self.assertEqual(
response.data["partij_identificator"]["code_register"],
PartijIdentificatorCodeRegister.overige,
)


class CategorieRelatieTests(APITestCase):
def test_list_categorie_relatie(self):
Expand Down
Loading

0 comments on commit d395b24

Please sign in to comment.