Skip to content

Commit d395b24

Browse files
[#233] Change field type
[#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
1 parent 240d965 commit d395b24

File tree

5 files changed

+481
-38
lines changed

5 files changed

+481
-38
lines changed

src/openklant/components/klantinteracties/api/tests/test_partijen.py

Lines changed: 246 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import datetime
22

3+
from django.core.exceptions import ValidationError
34
from django.utils.translation import gettext as _
45

56
from rest_framework import status
67
from vng_api_common.tests import reverse
78

8-
from openklant.components.klantinteracties.models.constants import SoortPartij
9+
from openklant.components.klantinteracties.models.constants import (
10+
PartijIdentificatorCodeObjectType,
11+
PartijIdentificatorCodeRegister,
12+
PartijIdentificatorCodeSoortObjectId,
13+
SoortPartij,
14+
)
915
from openklant.components.klantinteracties.models.partijen import Partij
1016
from openklant.components.klantinteracties.models.tests.factories.digitaal_adres import (
1117
DigitaalAdresFactory,
@@ -1873,10 +1879,10 @@ def test_create_partij_indetificator(self):
18731879
"identificeerdePartij": {"uuid": str(partij.uuid)},
18741880
"anderePartijIdentificator": "anderePartijIdentificator",
18751881
"partijIdentificator": {
1876-
"codeObjecttype": "codeObjecttype",
1877-
"codeSoortObjectId": "codeSoortObjectId",
1878-
"objectId": "objectId",
1879-
"codeRegister": "codeRegister",
1882+
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
1883+
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
1884+
"objectId": "123456788",
1885+
"codeRegister": PartijIdentificatorCodeRegister.brp,
18801886
},
18811887
}
18821888

@@ -1889,10 +1895,10 @@ def test_create_partij_indetificator(self):
18891895
self.assertEqual(
18901896
data["partijIdentificator"],
18911897
{
1892-
"codeObjecttype": "codeObjecttype",
1893-
"codeSoortObjectId": "codeSoortObjectId",
1894-
"objectId": "objectId",
1895-
"codeRegister": "codeRegister",
1898+
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
1899+
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
1900+
"objectId": "123456788",
1901+
"codeRegister": PartijIdentificatorCodeRegister.brp,
18961902
},
18971903
)
18981904

@@ -1901,10 +1907,10 @@ def test_update_partij_indetificator(self):
19011907
partij_identificator = PartijIdentificatorFactory.create(
19021908
partij=partij,
19031909
andere_partij_identificator="anderePartijIdentificator",
1904-
partij_identificator_code_objecttype="codeObjecttype",
1905-
partij_identificator_code_soort_object_id="codeSoortObjectId",
1906-
partij_identificator_object_id="objectId",
1907-
partij_identificator_code_register="codeRegister",
1910+
partij_identificator_code_objecttype=PartijIdentificatorCodeObjectType.natuurlijk_persoon,
1911+
partij_identificator_code_soort_object_id=PartijIdentificatorCodeSoortObjectId.bsn,
1912+
partij_identificator_object_id="123456788",
1913+
partij_identificator_code_register=PartijIdentificatorCodeRegister.brp,
19081914
)
19091915

19101916
detail_url = reverse(
@@ -1919,21 +1925,21 @@ def test_update_partij_indetificator(self):
19191925
self.assertEqual(
19201926
data["partijIdentificator"],
19211927
{
1922-
"codeObjecttype": "codeObjecttype",
1923-
"codeSoortObjectId": "codeSoortObjectId",
1924-
"objectId": "objectId",
1925-
"codeRegister": "codeRegister",
1928+
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
1929+
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
1930+
"objectId": "123456788",
1931+
"codeRegister": PartijIdentificatorCodeRegister.brp,
19261932
},
19271933
)
19281934

19291935
data = {
19301936
"identificeerdePartij": {"uuid": str(partij2.uuid)},
19311937
"anderePartijIdentificator": "changed",
19321938
"partijIdentificator": {
1933-
"codeObjecttype": "changed",
1934-
"codeSoortObjectId": "changed",
1935-
"objectId": "changed",
1936-
"codeRegister": "changed",
1939+
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
1940+
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
1941+
"objectId": "123456789",
1942+
"codeRegister": PartijIdentificatorCodeRegister.brp,
19371943
},
19381944
}
19391945

@@ -1946,10 +1952,10 @@ def test_update_partij_indetificator(self):
19461952
self.assertEqual(
19471953
data["partijIdentificator"],
19481954
{
1949-
"codeObjecttype": "changed",
1950-
"codeSoortObjectId": "changed",
1951-
"objectId": "changed",
1952-
"codeRegister": "changed",
1955+
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
1956+
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
1957+
"objectId": "123456789",
1958+
"codeRegister": PartijIdentificatorCodeRegister.brp,
19531959
},
19541960
)
19551961

@@ -1958,10 +1964,10 @@ def test_partial_update_partij_indetificator(self):
19581964
partij_identificator = PartijIdentificatorFactory.create(
19591965
partij=partij,
19601966
andere_partij_identificator="anderePartijIdentificator",
1961-
partij_identificator_code_objecttype="codeObjecttype",
1962-
partij_identificator_code_soort_object_id="codeSoortObjectId",
1963-
partij_identificator_object_id="objectId",
1964-
partij_identificator_code_register="codeRegister",
1967+
partij_identificator_code_objecttype=PartijIdentificatorCodeObjectType.natuurlijk_persoon,
1968+
partij_identificator_code_soort_object_id=PartijIdentificatorCodeSoortObjectId.bsn,
1969+
partij_identificator_object_id="123456788",
1970+
partij_identificator_code_register=PartijIdentificatorCodeRegister.brp,
19651971
)
19661972

19671973
detail_url = reverse(
@@ -1976,10 +1982,10 @@ def test_partial_update_partij_indetificator(self):
19761982
self.assertEqual(
19771983
data["partijIdentificator"],
19781984
{
1979-
"codeObjecttype": "codeObjecttype",
1980-
"codeSoortObjectId": "codeSoortObjectId",
1981-
"objectId": "objectId",
1982-
"codeRegister": "codeRegister",
1985+
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
1986+
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
1987+
"objectId": "123456788",
1988+
"codeRegister": PartijIdentificatorCodeRegister.brp,
19831989
},
19841990
)
19851991

@@ -1996,10 +2002,10 @@ def test_partial_update_partij_indetificator(self):
19962002
self.assertEqual(
19972003
data["partijIdentificator"],
19982004
{
1999-
"codeObjecttype": "codeObjecttype",
2000-
"codeSoortObjectId": "codeSoortObjectId",
2001-
"objectId": "objectId",
2002-
"codeRegister": "codeRegister",
2005+
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
2006+
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
2007+
"objectId": "123456788",
2008+
"codeRegister": PartijIdentificatorCodeRegister.brp,
20032009
},
20042010
)
20052011

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

2026+
def test_invalid_choice_partij_identificator_code_register(self):
2027+
url = reverse("klantinteracties:partijidentificator-list")
2028+
partij = PartijFactory.create()
2029+
data = {
2030+
"identificeerdePartij": {"uuid": str(partij.uuid)},
2031+
"anderePartijIdentificator": "anderePartijIdentificator",
2032+
"partijIdentificator": {
2033+
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
2034+
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
2035+
"objectId": 12,
2036+
"codeRegister": "test",
2037+
},
2038+
}
2039+
response = self.client.post(url, data)
2040+
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
2041+
self.assertEqual(response.data["code"], "invalid")
2042+
self.assertEqual(response.data["title"], "Invalid input.")
2043+
self.assertEqual(
2044+
response.data["invalid_params"][0]["name"],
2045+
"partijIdentificator.codeRegister",
2046+
)
2047+
self.assertEqual(response.data["invalid_params"][0]["code"], "invalid_choice")
2048+
self.assertEqual(
2049+
response.data["invalid_params"][0]["reason"],
2050+
'"test" is een ongeldige keuze.',
2051+
)
2052+
2053+
def test_invalid_choice_partij_identificator_code_objecttype(self):
2054+
url = reverse("klantinteracties:partijidentificator-list")
2055+
partij = PartijFactory.create()
2056+
data = {
2057+
"identificeerdePartij": {"uuid": str(partij.uuid)},
2058+
"anderePartijIdentificator": "anderePartijIdentificator",
2059+
"partijIdentificator": {
2060+
"codeObjecttype": "test",
2061+
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
2062+
"objectId": 12,
2063+
"codeRegister": PartijIdentificatorCodeRegister.brp,
2064+
},
2065+
}
2066+
response = self.client.post(url, data)
2067+
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
2068+
self.assertEqual(response.data["code"], "invalid")
2069+
self.assertEqual(response.data["title"], "Invalid input.")
2070+
self.assertEqual(
2071+
response.data["invalid_params"][0]["name"],
2072+
"partijIdentificator.codeObjecttype",
2073+
)
2074+
self.assertEqual(response.data["invalid_params"][0]["code"], "invalid_choice")
2075+
self.assertEqual(
2076+
response.data["invalid_params"][0]["reason"],
2077+
'"test" is een ongeldige keuze.',
2078+
)
2079+
2080+
def test_invalid_choice_partij_identificator_code_soort_object_id(self):
2081+
url = reverse("klantinteracties:partijidentificator-list")
2082+
partij = PartijFactory.create()
2083+
data = {
2084+
"identificeerdePartij": {"uuid": str(partij.uuid)},
2085+
"anderePartijIdentificator": "anderePartijIdentificator",
2086+
"partijIdentificator": {
2087+
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
2088+
"codeSoortObjectId": "test",
2089+
"objectId": 12,
2090+
"codeRegister": PartijIdentificatorCodeRegister.brp,
2091+
},
2092+
}
2093+
response = self.client.post(url, data)
2094+
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
2095+
self.assertEqual(response.data["code"], "invalid")
2096+
self.assertEqual(response.data["title"], "Invalid input.")
2097+
self.assertEqual(
2098+
response.data["invalid_params"][0]["name"],
2099+
"partijIdentificator.codeSoortObjectId",
2100+
)
2101+
self.assertEqual(response.data["invalid_params"][0]["code"], "invalid_choice")
2102+
self.assertEqual(
2103+
response.data["invalid_params"][0]["reason"],
2104+
'"test" is een ongeldige keuze.',
2105+
)
2106+
2107+
def test_invalid_validation_partij_identificator_code_objecttype(self):
2108+
url = reverse("klantinteracties:partijidentificator-list")
2109+
partij = PartijFactory.create()
2110+
data = {
2111+
"identificeerdePartij": {"uuid": str(partij.uuid)},
2112+
"anderePartijIdentificator": "anderePartijIdentificator",
2113+
"partijIdentificator": {
2114+
"codeObjecttype": PartijIdentificatorCodeObjectType.niet_natuurlijk_persoon,
2115+
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
2116+
"objectId": 12,
2117+
"codeRegister": PartijIdentificatorCodeRegister.brp,
2118+
},
2119+
}
2120+
2121+
with self.assertRaisesMessage(
2122+
ValidationError, "ObjectType keuzes zijn beperkt op basis van Register"
2123+
):
2124+
self.client.post(url, data)
2125+
2126+
def test_invalid_validation_partij_identificator_code_soort_object_id(self):
2127+
url = reverse("klantinteracties:partijidentificator-list")
2128+
partij = PartijFactory.create()
2129+
data = {
2130+
"identificeerdePartij": {"uuid": str(partij.uuid)},
2131+
"anderePartijIdentificator": "anderePartijIdentificator",
2132+
"partijIdentificator": {
2133+
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
2134+
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.kvknummer,
2135+
"objectId": 12,
2136+
"codeRegister": PartijIdentificatorCodeRegister.brp,
2137+
},
2138+
}
2139+
2140+
with self.assertRaisesMessage(
2141+
ValidationError,
2142+
"CodeSoortObjectIdValidator keuzes zijn beperkt op basis van CodeObjectType",
2143+
):
2144+
self.client.post(url, data)
2145+
2146+
def test_invalid_validation_partij_identificator_object_id(self):
2147+
url = reverse("klantinteracties:partijidentificator-list")
2148+
partij = PartijFactory.create()
2149+
data = {
2150+
"identificeerdePartij": {"uuid": str(partij.uuid)},
2151+
"anderePartijIdentificator": "anderePartijIdentificator",
2152+
"partijIdentificator": {
2153+
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
2154+
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
2155+
"objectId": 12,
2156+
"codeRegister": PartijIdentificatorCodeRegister.brp,
2157+
},
2158+
}
2159+
2160+
with self.assertRaisesMessage(
2161+
ValidationError, "De lengte van de ObjectId moet tussen 8 en 9 liggen."
2162+
):
2163+
self.client.post(url, data)
2164+
2165+
def test_valid_validation_partij_identificator(self):
2166+
# All validations pass
2167+
url = reverse("klantinteracties:partijidentificator-list")
2168+
partij = PartijFactory.create()
2169+
data = {
2170+
"identificeerdePartij": {"uuid": str(partij.uuid)},
2171+
"anderePartijIdentificator": "anderePartijIdentificator",
2172+
"partijIdentificator": {
2173+
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
2174+
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.bsn,
2175+
"objectId": 123456789,
2176+
"codeRegister": PartijIdentificatorCodeRegister.brp,
2177+
},
2178+
}
2179+
response = self.client.post(url, data)
2180+
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
2181+
self.assertEqual(
2182+
response.data["partij_identificator"]["code_objecttype"],
2183+
PartijIdentificatorCodeObjectType.natuurlijk_persoon,
2184+
)
2185+
self.assertEqual(
2186+
response.data["partij_identificator"]["code_soort_object_id"],
2187+
PartijIdentificatorCodeSoortObjectId.bsn,
2188+
)
2189+
self.assertEqual(
2190+
response.data["partij_identificator"]["object_id"], "123456789"
2191+
)
2192+
self.assertEqual(
2193+
response.data["partij_identificator"]["code_register"],
2194+
PartijIdentificatorCodeRegister.brp,
2195+
)
2196+
2197+
def test_valid_overige_validation_partij_identificator(self):
2198+
# Overige no validation
2199+
url = reverse("klantinteracties:partijidentificator-list")
2200+
partij = PartijFactory.create()
2201+
data = {
2202+
"identificeerdePartij": {"uuid": str(partij.uuid)},
2203+
"anderePartijIdentificator": "anderePartijIdentificator",
2204+
"partijIdentificator": {
2205+
"codeObjecttype": PartijIdentificatorCodeObjectType.natuurlijk_persoon,
2206+
"codeSoortObjectId": PartijIdentificatorCodeSoortObjectId.rsin,
2207+
"objectId": 123456789,
2208+
"codeRegister": PartijIdentificatorCodeRegister.overige,
2209+
},
2210+
}
2211+
response = self.client.post(url, data)
2212+
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
2213+
self.assertEqual(
2214+
response.data["partij_identificator"]["code_objecttype"],
2215+
PartijIdentificatorCodeObjectType.natuurlijk_persoon,
2216+
)
2217+
self.assertEqual(
2218+
response.data["partij_identificator"]["code_soort_object_id"],
2219+
PartijIdentificatorCodeSoortObjectId.rsin,
2220+
)
2221+
self.assertEqual(
2222+
response.data["partij_identificator"]["object_id"], "123456789"
2223+
)
2224+
self.assertEqual(
2225+
response.data["partij_identificator"]["code_register"],
2226+
PartijIdentificatorCodeRegister.overige,
2227+
)
2228+
20202229

20212230
class CategorieRelatieTests(APITestCase):
20222231
def test_list_categorie_relatie(self):

0 commit comments

Comments
 (0)