1
1
import datetime
2
2
3
+ from django .core .exceptions import ValidationError
3
4
from django .utils .translation import gettext as _
4
5
5
6
from rest_framework import status
6
7
from vng_api_common .tests import reverse
7
8
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
+ )
9
15
from openklant .components .klantinteracties .models .partijen import Partij
10
16
from openklant .components .klantinteracties .models .tests .factories .digitaal_adres import (
11
17
DigitaalAdresFactory ,
@@ -1873,10 +1879,10 @@ def test_create_partij_indetificator(self):
1873
1879
"identificeerdePartij" : {"uuid" : str (partij .uuid )},
1874
1880
"anderePartijIdentificator" : "anderePartijIdentificator" ,
1875
1881
"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 ,
1880
1886
},
1881
1887
}
1882
1888
@@ -1889,10 +1895,10 @@ def test_create_partij_indetificator(self):
1889
1895
self .assertEqual (
1890
1896
data ["partijIdentificator" ],
1891
1897
{
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 ,
1896
1902
},
1897
1903
)
1898
1904
@@ -1901,10 +1907,10 @@ def test_update_partij_indetificator(self):
1901
1907
partij_identificator = PartijIdentificatorFactory .create (
1902
1908
partij = partij ,
1903
1909
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 ,
1908
1914
)
1909
1915
1910
1916
detail_url = reverse (
@@ -1919,21 +1925,21 @@ def test_update_partij_indetificator(self):
1919
1925
self .assertEqual (
1920
1926
data ["partijIdentificator" ],
1921
1927
{
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 ,
1926
1932
},
1927
1933
)
1928
1934
1929
1935
data = {
1930
1936
"identificeerdePartij" : {"uuid" : str (partij2 .uuid )},
1931
1937
"anderePartijIdentificator" : "changed" ,
1932
1938
"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 ,
1937
1943
},
1938
1944
}
1939
1945
@@ -1946,10 +1952,10 @@ def test_update_partij_indetificator(self):
1946
1952
self .assertEqual (
1947
1953
data ["partijIdentificator" ],
1948
1954
{
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 ,
1953
1959
},
1954
1960
)
1955
1961
@@ -1958,10 +1964,10 @@ def test_partial_update_partij_indetificator(self):
1958
1964
partij_identificator = PartijIdentificatorFactory .create (
1959
1965
partij = partij ,
1960
1966
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 ,
1965
1971
)
1966
1972
1967
1973
detail_url = reverse (
@@ -1976,10 +1982,10 @@ def test_partial_update_partij_indetificator(self):
1976
1982
self .assertEqual (
1977
1983
data ["partijIdentificator" ],
1978
1984
{
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 ,
1983
1989
},
1984
1990
)
1985
1991
@@ -1996,10 +2002,10 @@ def test_partial_update_partij_indetificator(self):
1996
2002
self .assertEqual (
1997
2003
data ["partijIdentificator" ],
1998
2004
{
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 ,
2003
2009
},
2004
2010
)
2005
2011
@@ -2017,6 +2023,209 @@ def test_destroy_partij_identificator(self):
2017
2023
data = response .json ()
2018
2024
self .assertEqual (data ["count" ], 0 )
2019
2025
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
+
2020
2229
2021
2230
class CategorieRelatieTests (APITestCase ):
2022
2231
def test_list_categorie_relatie (self ):
0 commit comments