Skip to content

Commit 5c1543e

Browse files
[#239] New tests
1 parent 2a8e8a8 commit 5c1543e

File tree

6 files changed

+444
-58
lines changed

6 files changed

+444
-58
lines changed

src/openklant/components/contactgegevens/api/schema.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.conf import settings
22
from django.utils.translation import gettext_lazy as _
33

4-
description = _(
4+
DESCRIPTION = _(
55
"""
66
**Warning: Difference between `PUT` and `PATCH`**
77
@@ -19,7 +19,7 @@
1919

2020
custom_settings = {
2121
"TITLE": "contactgegevens",
22-
"DESCRIPTION": description,
22+
"DESCRIPTION": DESCRIPTION,
2323
"VERSION": settings.CONTACTGEGEVENS_API_VERSION,
2424
"SERVERS": [{"url": "/contactgegevens/api/v1"}],
2525
"TAGS": [

src/openklant/components/klantinteracties/api/schema.py

+32-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.conf import settings
22
from django.utils.translation import gettext_lazy as _
33

4-
description = _(
4+
DESCRIPTION = _(
55
"""
66
**Warning: Difference between `PUT` and `PATCH`**
77
@@ -16,7 +16,34 @@
1616
leaving other fields unchanged.
1717
"""
1818
)
19-
partijen_description = _(
19+
PARTIJ_IDENTIFICATOR_DESCRIPTION_CREATE = _(
20+
"""
21+
**Warnings:**
22+
23+
Handles `partijIdentificatoren` creation with atomicity guarantees.
24+
25+
- If the `UUID` is provided in the `PartijIdentificator` object,
26+
the endpoint will treat it as an update operation for the existing `PartijIdentificator`,
27+
applying the provided data and linking the parent `Partij` to the new one created.
28+
- If the `UUID` is **not** specified, the system will create a new
29+
`PartijIdentificator` instance respecting all uniqueness constraints.
30+
"""
31+
)
32+
33+
PARTIJ_IDENTIFICATOR_DESCRIPTION_UPDATE = _(
34+
"""
35+
**Warnings:**
36+
37+
Handles `partijIdentificatoren` updates with atomicity guarantees.
38+
39+
- If the `UUID` is provided in the `PartijIdentificator` object,
40+
the system will update the specified instance with the new data.
41+
- If the `UUID` is **not** specified, the system will `DELETE` all `PartijIdentificator`
42+
objects related to the parent and `CREATE` new ones with the new passed data.
43+
"""
44+
)
45+
46+
PARTIJEN_DESCRIPTION = _(
2047
"""
2148
**Atomicity in Partij and PartijIdentificator**
2249
@@ -27,28 +54,13 @@
2754
2855
For `POST`, `PATCH`, and `PUT` requests for `Partij`,
2956
it is possible to send a list of `PartijIdentificator` objects.
30-
31-
**Warnings:**
32-
33-
- In all requests, `PartijIdentificator` objects should not contain the **UUID**
34-
of the parent `Partij`, because it is automatically assigned.
35-
- `POST` request:
36-
- If the **UUID** is provided in the `PartijIdentificator` object,
37-
the endpoint will treat it as an update operation for the existing `PartijIdentificator`,
38-
applying the provided data and linking the parent `Partij` to the new one created.
39-
- If the **UUID** is **not** specified, the system will create a new
40-
`PartijIdentificator` instance respecting all uniqueness constraints.
41-
- `PATCH` or `PUT` requests:
42-
- If the **UUID** is provided in the `PartijIdentificator` object,
43-
the system will update the specified instance with the new data.
44-
- If the **UUID** is **not** specified, the system will `DELETE` all `PartijIdentificator`
45-
objects related to the parent and `CREATE` new ones with the passed data.
4657
"""
4758
)
4859

60+
4961
custom_settings = {
5062
"TITLE": "klantinteracties",
51-
"DESCRIPTION": description,
63+
"DESCRIPTION": DESCRIPTION,
5264
"VERSION": settings.KLANTINTERACTIES_API_VERSION,
5365
"SERVERS": [{"url": "/klantinteracties/api/v1"}],
5466
"TAGS": [
@@ -63,7 +75,7 @@
6375
{"name": "klanten contacten"},
6476
{"name": "onderwerpobjecten"},
6577
{"name": "partij-identificatoren"},
66-
{"name": "partijen", "description": partijen_description},
78+
{"name": "partijen", "description": PARTIJEN_DESCRIPTION},
6779
{"name": "rekeningnummers"},
6880
{"name": "vertegenwoordigingen"},
6981
],

src/openklant/components/klantinteracties/api/serializers/partijen.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -603,19 +603,12 @@ def get_vertegenwoordigden(self, obj):
603603

604604
def validate_partij_identificatoren(self, attrs):
605605
if attrs:
606-
if (
607-
len(
608-
Counter(
609-
item["partij"] for item in attrs if item["partij"] is not None
610-
)
611-
)
612-
> 0
613-
):
606+
if any(item["partij"] is not None for item in attrs):
614607
raise serializers.ValidationError(
615608
{
616609
"identificeerdePartij": _(
617610
"Het veld `identificeerde_partij` wordt automatisch ingesteld en"
618-
" hoeft niet te worden opgegeven."
611+
" dient niet te worden opgegeven."
619612
)
620613
},
621614
code="invalid",
@@ -655,6 +648,7 @@ def update_or_create_partij_identificator(self, partij_identificator):
655648
partij_identificator_serializer.validated_data
656649
)
657650

651+
@handle_db_exceptions
658652
@transaction.atomic
659653
def update(self, instance, validated_data):
660654
method = self.context.get("request").method
@@ -831,6 +825,7 @@ def update(self, instance, validated_data):
831825

832826
return partij
833827

828+
@handle_db_exceptions
834829
@transaction.atomic
835830
def create(self, validated_data):
836831
partij_identificatie = validated_data.pop("partij_identificatie", None)

0 commit comments

Comments
 (0)