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

Feature/233 fix values partij identificatoren #291

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
Vertegenwoordigden,
)
from openklant.components.klantinteracties.models.rekeningnummers import Rekeningnummer
from openklant.components.klantinteracties.models.validators import (
PartijIdentificatorValidator,
)
from openklant.utils.serializers import get_field_value


class PartijForeignkeyBaseSerializer(serializers.HyperlinkedModelSerializer):
Expand Down Expand Up @@ -399,6 +403,11 @@ class Meta:
},
}

def validate(self, attrs):
partij_identificator = get_field_value(self, attrs, "partij_identificator")
PartijIdentificatorValidator(**partij_identificator).validate()
return super().validate(attrs)

@transaction.atomic
def update(self, instance, validated_data):
if "partij" in validated_data:
Expand Down
29 changes: 17 additions & 12 deletions src/openklant/components/klantinteracties/api/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,16 +694,17 @@ def test_filter_vertegenwoordigde_partij_url(self):
def test_filter_partij_identificator_code_objecttype(self):
partij, partij2 = PartijFactory.create_batch(2)
PartijIdentificatorFactory.create(
partij=partij, partij_identificator_code_objecttype="one"
partij=partij, partij_identificator_code_objecttype="natuurlijk_persoon"
)
PartijIdentificatorFactory.create(
partij=partij2, partij_identificator_code_objecttype="two"
partij=partij2,
partij_identificator_code_objecttype="niet_natuurlijk_persoon",
)

with self.subTest("happy flow"):
response = self.client.get(
self.url,
{"partijIdentificator__codeObjecttype": "two"},
{"partijIdentificator__codeObjecttype": "niet_natuurlijk_persoon"},
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand All @@ -724,16 +725,16 @@ def test_filter_partij_identificator_code_objecttype(self):
def test_filter_identificator_soort_object_id(self):
partij, partij2 = PartijFactory.create_batch(2)
PartijIdentificatorFactory.create(
partij=partij, partij_identificator_code_soort_object_id="one"
partij=partij, partij_identificator_code_soort_object_id="bsn"
)
PartijIdentificatorFactory.create(
partij=partij2, partij_identificator_code_soort_object_id="two"
partij=partij2, partij_identificator_code_soort_object_id="kvknummer"
)

with self.subTest("happy flow"):
response = self.client.get(
self.url,
{"partijIdentificator__codeSoortObjectId": "one"},
{"partijIdentificator__codeSoortObjectId": "bsn"},
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand All @@ -756,16 +757,20 @@ def test_filter_identificator_soort_object_id(self):
def test_filter_identificator_object_id(self):
partij, partij2 = PartijFactory.create_batch(2)
PartijIdentificatorFactory.create(
partij=partij, partij_identificator_object_id="one"
partij=partij,
partij_identificator_code_soort_object_id="bsn",
partij_identificator_object_id="296648875",
)
PartijIdentificatorFactory.create(
partij=partij2, partij_identificator_object_id="two"
partij=partij2,
partij_identificator_code_soort_object_id="bsn",
partij_identificator_object_id="111222333",
)

with self.subTest("happy flow"):
response = self.client.get(
self.url,
{"partijIdentificator__objectId": "one"},
{"partijIdentificator__objectId": "296648875"},
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand All @@ -786,16 +791,16 @@ def test_filter_identificator_object_id(self):
def test_filter_identificator_code_register(self):
partij, partij2 = PartijFactory.create_batch(2)
PartijIdentificatorFactory.create(
partij=partij, partij_identificator_code_register="one"
partij=partij, partij_identificator_code_register="brp"
)
PartijIdentificatorFactory.create(
partij=partij2, partij_identificator_code_register="two"
partij=partij2, partij_identificator_code_register="hr"
)

with self.subTest("happy flow"):
response = self.client.get(
self.url,
{"partijIdentificator__code_register": "two"},
{"partijIdentificator__code_register": "hr"},
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand Down
Loading
Loading