Skip to content

Commit

Permalink
[#233] Use variables in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmursa-dev committed Dec 19, 2024
1 parent 3572dc7 commit e68104c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 70 deletions.
130 changes: 62 additions & 68 deletions src/openklant/components/klantinteracties/api/tests/test_partijen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
from rest_framework import status
from vng_api_common.tests import reverse

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

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

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

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

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

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

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

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

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

Expand All @@ -2034,9 +2029,9 @@ def test_invalid_choice_partij_identificator_code_register(self):
"identificeerdePartij": {"uuid": str(partij.uuid)},
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"objectId": 12,
"codeObjecttype": "natuurlijk_persoon",
"codeSoortObjectId": "bsn",
"objectId": "123456789",
"codeRegister": "test",
},
}
Expand All @@ -2062,9 +2057,9 @@ def test_invalid_choice_partij_identificator_code_objecttype(self):
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": "test",
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"objectId": 12,
"codeRegister": PartijIdentificatorCodeRegister.brp,
"codeSoortObjectId": "bsn",
"objectId": "123456789",
"codeRegister": "brp",
},
}
response = self.client.post(url, data)
Expand All @@ -2088,10 +2083,10 @@ def test_invalid_choice_partij_identificator_code_soort_object_id(self):
"identificeerdePartij": {"uuid": str(partij.uuid)},
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeObjecttype": "natuurlijk_persoon",
"codeSoortObjectId": "test",
"objectId": 12,
"codeRegister": PartijIdentificatorCodeRegister.brp,
"objectId": "123456789",
"codeRegister": "brp",
},
}
response = self.client.post(url, data)
Expand All @@ -2115,10 +2110,10 @@ def test_invalid_validation_partij_identificator_code_objecttype(self):
"identificeerdePartij": {"uuid": str(partij.uuid)},
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": PartijIdentificatorCodeObjectType.niet_natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"objectId": 12,
"codeRegister": PartijIdentificatorCodeRegister.brp,
"codeObjecttype": "niet_natuurlijk_persoon",
"codeSoortObjectId": "bsn",
"objectId": "123456789",
"codeRegister": "brp",
},
}

Expand All @@ -2134,13 +2129,12 @@ def test_invalid_validation_partij_identificator_code_soort_object_id(self):
"identificeerdePartij": {"uuid": str(partij.uuid)},
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.kvknummer,
"objectId": 12,
"codeRegister": PartijIdentificatorCodeRegister.brp,
"codeObjecttype": "natuurlijk_persoon",
"codeSoortObjectId": "kvk_nummer",
"objectId": "123456789",
"codeRegister": "brp",
},
}

with self.assertRaisesMessage(
ValidationError,
"CodeSoortObjectId keuzes zijn beperkt op basis van CodeObjectType.",
Expand All @@ -2154,10 +2148,10 @@ def test_invalid_validation_partij_identificator_object_id(self):
"identificeerdePartij": {"uuid": str(partij.uuid)},
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"objectId": 12,
"codeRegister": PartijIdentificatorCodeRegister.brp,
"codeObjecttype": "natuurlijk_persoon",
"codeSoortObjectId": "bsn",
"objectId": "12",
"codeRegister": "brp",
},
}

Expand All @@ -2174,28 +2168,28 @@ def test_valid_validation_partij_identificator(self):
"identificeerdePartij": {"uuid": str(partij.uuid)},
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"objectId": 123456789,
"codeRegister": PartijIdentificatorCodeRegister.brp,
"codeObjecttype": "natuurlijk_persoon",
"codeSoortObjectId": "bsn",
"objectId": "123456789",
"codeRegister": "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,
"natuurlijk_persoon",
)
self.assertEqual(
response.data["partij_identificator"]["code_soort_object_id"],
PartijIdentificatorCodeSoortObjectId.bsn,
"bsn",
)
self.assertEqual(
response.data["partij_identificator"]["object_id"], "123456789"
)
self.assertEqual(
response.data["partij_identificator"]["code_register"],
PartijIdentificatorCodeRegister.brp,
"brp",
)

def test_valid_overige_validation_partij_identificator(self):
Expand All @@ -2206,28 +2200,28 @@ def test_valid_overige_validation_partij_identificator(self):
"identificeerdePartij": {"uuid": str(partij.uuid)},
"anderePartijIdentificator": "anderePartijIdentificator",
"partijIdentificator": {
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
"codeObjecttype": "natuurlijk_persoon",
"codeSoortObjectId": "bsn",
"objectId": 123456789,
"codeRegister": PartijIdentificatorCodeRegister.overige,
"codeRegister": "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,
"natuurlijk_persoon",
)
self.assertEqual(
response.data["partij_identificator"]["code_soort_object_id"],
PartijIdentificatorCodeSoortObjectId.bsn,
"bsn",
)
self.assertEqual(
response.data["partij_identificator"]["object_id"], "123456789"
)
self.assertEqual(
response.data["partij_identificator"]["code_register"],
PartijIdentificatorCodeRegister.overige,
"overige",
)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.15 on 2024-12-18 11:21
# Generated by Django 4.2.15 on 2024-12-19 13:42

import django.core.validators
from django.db import migrations, models
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def validate_code_object_type(self) -> None:

def validate_code_soort_object_id(self) -> None:
"""Validates the CodeSoortObjectId based on register and CodeObjectType"""

if not self.code_soort_object_id:
return

Expand Down

0 comments on commit e68104c

Please sign in to comment.