|
| 1 | +from django.core.exceptions import ValidationError |
| 2 | +from django.test import TestCase |
| 3 | + |
| 4 | +from openklant.components.klantinteracties.models.constants import ( |
| 5 | + PartijIdentificatorCodeObjectType, |
| 6 | + PartijIdentificatorCodeRegister, |
| 7 | + PartijIdentificatorCodeSoortObjectId, |
| 8 | +) |
| 9 | +from openklant.components.klantinteracties.models.partijen import ( |
| 10 | + Partij, |
| 11 | + PartijIdentificator, |
| 12 | +) |
| 13 | +from openklant.components.klantinteracties.models.tests.factories.partijen import ( |
| 14 | + PartijFactory, |
| 15 | +) |
| 16 | + |
| 17 | +""" |
| 18 | +# ALLOWED only one time, because it does not exist in any partij |
| 19 | +- partij_identificator(partij=partij, soortObjectId='bsn', object_id=123) |
| 20 | +
|
| 21 | +# NOT ALLOWED because already exists one bsn for the same partij |
| 22 | +- partij_identificator(partij=partij, soortObjectId='bsn', object_id=456) |
| 23 | +
|
| 24 | +# NOT ALLOWED because already exists one bsn=123 for another partij |
| 25 | +- partij_identificator(partij=partij1, soortObjectId='bsn', object_id=123) |
| 26 | +
|
| 27 | +# ALLOWED only one time because vestigingsnummer=None |
| 28 | +- partij_identificator(partij=partij1, soortObjectId='kvk', object_id=123) |
| 29 | +
|
| 30 | +# NOT ALLOWED because already exist one kvk_nummer=123 without vestigingsnummer in any partij |
| 31 | +- partij_identificator(partij=partij2, soortObjectId='kvk', object_id=123) |
| 32 | +
|
| 33 | +# ALLOWED only one time, SAME kvk (123) NEW vestigingsnummer(123) |
| 34 | +- partij_identificator(partij=partij3, soortObjectId='kvk', object_id=123) |
| 35 | +- partij_identificator(partij=partij3, soortObjectId='vestigingsnummer', object_id=123) |
| 36 | +
|
| 37 | +# NOT ALLOWED beacuse arleady exists this combination |
| 38 | +- partij_identificator(partij=partij4, soortObjectId='kvk', object_id=123) |
| 39 | +- partij_identificator(partij=partij4, soortObjectId='vestigingsnummer', object_id=123) |
| 40 | +
|
| 41 | +# ALLOWED only one time, SAME kvk (123) NEW vestigingsnummer(456) |
| 42 | +- partij_identificator(partij=partij5, soortObjectId='kvk', object_id=123) |
| 43 | +- partij_identificator(partij=partij5, soortObjectId='vestigingsnummer', object_id=456) |
| 44 | +
|
| 45 | +# ALLOWED only one time, NEW kvk (456) SAME vestigingsnummer(456) |
| 46 | +- partij_identificator(partij=partij6, soortObjectId='kvk', object_id=456) |
| 47 | +- partij_identificator(partij=partij6, soortObjectId='vestigingsnummer', object_id=456) |
| 48 | +
|
| 49 | + Specificando Partij |
| 50 | + test_bsn |
| 51 | + test_1_bsn_in_partij |
| 52 | + test_n_bsn_in_partij |
| 53 | + test_1_bsn_in_multiple_partij |
| 54 | + test_n_bsn_in_multiple_partij |
| 55 | + test_diversin_bsn_in_diversi_partij |
| 56 | + test_same_bsn_in_diversi_partij |
| 57 | + test_bsn_non_deve_avere_il_parent |
| 58 | + |
| 59 | + |
| 60 | + test_kvk (uguali a bsn) |
| 61 | + test_kvk_in_partij |
| 62 | + test_kvk_in_partij_in_multiple_parti |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + Senza specificare il partij |
| 69 | + test_constraint_partij_identificator (prova a fare lo stesso object_id) |
| 70 | + test_constraint_partij_identificator (prova a fare con diversi object_id) |
| 71 | + |
| 72 | + |
| 73 | +
|
| 74 | + validator = PartijIdentificatorTypeValidator( |
| 75 | + code_objecttype="natuurlijk_persoon", |
| 76 | + code_soort_object_id="bsn", |
| 77 | + object_id="296648875", |
| 78 | + code_register=PartijIdentificatorCodeRegister.brp, |
| 79 | + ) |
| 80 | + validator.validate() |
| 81 | +""" |
| 82 | + |
| 83 | + |
| 84 | +class PartijIdentificatorModelConstraints(TestCase): |
| 85 | + def setUp(self): |
| 86 | + super().setUp() |
| 87 | + self.partij = PartijFactory.create(voorkeurs_digitaal_adres=None) |
| 88 | + |
| 89 | + def test_valid_scoped_identificator_globally_unique(self): |
| 90 | + PartijIdentificator.objects.create( |
| 91 | + sub_identificator_van=None, |
| 92 | + partij_identificator_code_objecttype="natuurlijk_persoon", |
| 93 | + partij_identificator_code_soort_object_id="bsn", |
| 94 | + partij_identificator_object_id="296648875", |
| 95 | + partij_identificator_code_register="brp", |
| 96 | + ) |
| 97 | + PartijIdentificator.objects.create( |
| 98 | + sub_identificator_van=None, |
| 99 | + partij_identificator_code_objecttype="niet_natuurlijk_persoon", |
| 100 | + partij_identificator_code_soort_object_id="rsin", |
| 101 | + partij_identificator_object_id="296648875", |
| 102 | + partij_identificator_code_register="hr", |
| 103 | + ) |
| 104 | + |
| 105 | + def test_valid_non_scoped_identificator_globally_unique_different_sub_identificator_van( |
| 106 | + self, |
| 107 | + ): |
| 108 | + partij_identificator_a = PartijIdentificator.objects.create( |
| 109 | + sub_identificator_van=None, |
| 110 | + partij_identificator_code_objecttype="niet_natuurlijk_persoon", |
| 111 | + partij_identificator_code_soort_object_id="kvk_nummer", |
| 112 | + partij_identificator_object_id="12345678", |
| 113 | + partij_identificator_code_register="hr", |
| 114 | + ) |
| 115 | + partij_identificator_b = PartijIdentificator.objects.create( |
| 116 | + sub_identificator_van=None, |
| 117 | + partij_identificator_code_objecttype="niet_natuurlijk_persoon", |
| 118 | + partij_identificator_code_soort_object_id="kvk_nummer", |
| 119 | + partij_identificator_object_id="87654321", |
| 120 | + partij_identificator_code_register="hr", |
| 121 | + ) |
| 122 | + |
| 123 | + PartijIdentificator.objects.create( |
| 124 | + sub_identificator_van=partij_identificator_a, |
| 125 | + partij_identificator_code_objecttype="vestiging", |
| 126 | + partij_identificator_code_soort_object_id="vestigingsnummer", |
| 127 | + partij_identificator_object_id="123412341234", |
| 128 | + partij_identificator_code_register="hr", |
| 129 | + ) |
| 130 | + |
| 131 | + PartijIdentificator.objects.create( |
| 132 | + sub_identificator_van=partij_identificator_b, |
| 133 | + partij_identificator_code_objecttype="vestiging", |
| 134 | + partij_identificator_code_soort_object_id="vestigingsnummer", |
| 135 | + partij_identificator_object_id="123412341234", |
| 136 | + partij_identificator_code_register="hr", |
| 137 | + ) |
| 138 | + |
| 139 | + def test_valid_non_scoped_identificator_globally_unique_different_values(self): |
| 140 | + partij_identificator = PartijIdentificator.objects.create( |
| 141 | + sub_identificator_van=None, |
| 142 | + partij_identificator_code_objecttype="niet_natuurlijk_persoon", |
| 143 | + partij_identificator_code_soort_object_id="kvk_nummer", |
| 144 | + partij_identificator_object_id="12345678", |
| 145 | + partij_identificator_code_register="hr", |
| 146 | + ) |
| 147 | + |
| 148 | + PartijIdentificator.objects.create( |
| 149 | + sub_identificator_van=partij_identificator, |
| 150 | + partij_identificator_code_objecttype="vestiging", |
| 151 | + partij_identificator_code_soort_object_id="vestigingsnummer", |
| 152 | + partij_identificator_object_id="123412341234", |
| 153 | + partij_identificator_code_register="hr", |
| 154 | + ) |
| 155 | + |
| 156 | + PartijIdentificator.objects.create( |
| 157 | + sub_identificator_van=partij_identificator, |
| 158 | + partij_identificator_code_objecttype="vestiging", |
| 159 | + partij_identificator_code_soort_object_id="vestigingsnummer", |
| 160 | + partij_identificator_object_id="987698769876", |
| 161 | + partij_identificator_code_register="hr", |
| 162 | + ) |
| 163 | + |
| 164 | + def test_invalid_scoped_identificator_globally_unique(self): |
| 165 | + return |
| 166 | + PartijIdentificator.objects.create( |
| 167 | + sub_identificator_van=None, |
| 168 | + partij_identificator_code_objecttype="natuurlijk_persoon", |
| 169 | + partij_identificator_code_soort_object_id="bsn", |
| 170 | + partij_identificator_object_id="296648875", |
| 171 | + partij_identificator_code_register="brp", |
| 172 | + ) |
| 173 | + PartijIdentificator.objects.create( |
| 174 | + sub_identificator_van=None, |
| 175 | + partij_identificator_code_objecttype="natuurlijk_persoon", |
| 176 | + partij_identificator_code_soort_object_id="bsn", |
| 177 | + partij_identificator_object_id="296648875", |
| 178 | + partij_identificator_code_register="brp", |
| 179 | + ) |
0 commit comments