Skip to content

Commit

Permalink
[#239] New tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmursa-dev committed Mar 11, 2025
1 parent f4a5a00 commit 7c0b655
Show file tree
Hide file tree
Showing 7 changed files with 1,250 additions and 816 deletions.
4 changes: 2 additions & 2 deletions src/openklant/components/contactgegevens/api/schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf import settings
from django.utils.translation import gettext_lazy as _

description = _(
DESCRIPTION = _(
"""
**Warning: Difference between `PUT` and `PATCH`**
Expand All @@ -19,7 +19,7 @@

custom_settings = {
"TITLE": "contactgegevens",
"DESCRIPTION": description,
"DESCRIPTION": DESCRIPTION,
"VERSION": settings.CONTACTGEGEVENS_API_VERSION,
"SERVERS": [{"url": "/contactgegevens/api/v1"}],
"TAGS": [
Expand Down
52 changes: 32 additions & 20 deletions src/openklant/components/klantinteracties/api/schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf import settings
from django.utils.translation import gettext_lazy as _

description = _(
DESCRIPTION = _(
"""
**Warning: Difference between `PUT` and `PATCH`**
Expand All @@ -16,7 +16,34 @@
leaving other fields unchanged.
"""
)
partijen_description = _(
PARTIJ_IDENTIFICATOR_DESCRIPTION_CREATE = _(
"""
**Warnings:**
Handles `partijIdentificatoren` creation with atomicity guarantees.
- If the `UUID` is provided in the `PartijIdentificator` object,
the endpoint will treat it as an update operation for the existing `PartijIdentificator`,
applying the provided data and linking the parent `Partij` to the new one created.
- If the `UUID` is **not** specified, the system will create a new
`PartijIdentificator` instance respecting all uniqueness constraints.
"""
)

PARTIJ_IDENTIFICATOR_DESCRIPTION_UPDATE = _(
"""
**Warnings:**
Handles `partijIdentificatoren` updates with atomicity guarantees.
- If the `UUID` is provided in the `PartijIdentificator` object,
the system will update the specified instance with the new data.
- If the `UUID` is **not** specified, the system will `DELETE` all `PartijIdentificator`
objects related to the parent and `CREATE` new ones with the new passed data.
"""
)

PARTIJEN_DESCRIPTION = _(
"""
**Atomicity in Partij and PartijIdentificator**
Expand All @@ -27,28 +54,13 @@
For `POST`, `PATCH`, and `PUT` requests for `Partij`,
it is possible to send a list of `PartijIdentificator` objects.
**Warnings:**
- In all requests, `PartijIdentificator` objects should not contain the **UUID**
of the parent `Partij`, because it is automatically assigned.
- `POST` request:
- If the **UUID** is provided in the `PartijIdentificator` object,
the endpoint will treat it as an update operation for the existing `PartijIdentificator`,
applying the provided data and linking the parent `Partij` to the new one created.
- If the **UUID** is **not** specified, the system will create a new
`PartijIdentificator` instance respecting all uniqueness constraints.
- `PATCH` or `PUT` requests:
- If the **UUID** is provided in the `PartijIdentificator` object,
the system will update the specified instance with the new data.
- If the **UUID** is **not** specified, the system will `DELETE` all `PartijIdentificator`
objects related to the parent and `CREATE` new ones with the passed data.
"""
)


custom_settings = {
"TITLE": "klantinteracties",
"DESCRIPTION": description,
"DESCRIPTION": DESCRIPTION,
"VERSION": settings.KLANTINTERACTIES_API_VERSION,
"SERVERS": [{"url": "/klantinteracties/api/v1"}],
"TAGS": [
Expand All @@ -63,7 +75,7 @@
{"name": "klanten contacten"},
{"name": "onderwerpobjecten"},
{"name": "partij-identificatoren"},
{"name": "partijen", "description": partijen_description},
{"name": "partijen", "description": PARTIJEN_DESCRIPTION},
{"name": "rekeningnummers"},
{"name": "vertegenwoordigingen"},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,25 +603,17 @@ def get_vertegenwoordigden(self, obj):

def validate_partij_identificatoren(self, attrs):
if attrs:
if (
len(
Counter(
item["partij"] for item in attrs if item["partij"] is not None
)
)
> 0
):
if any(item["partij"] is not None for item in attrs):
raise serializers.ValidationError(
{
"identificeerdePartij": _(
"Het veld `identificeerde_partij` wordt automatisch ingesteld en"
" hoeft niet te worden opgegeven."
" dient niet te worden opgegeven."
)
},
code="invalid",
)

uuid_list = [item["uuid"] for item in attrs if "uuid" in attrs]
uuid_list = [item["uuid"] for item in attrs if "uuid" in item]
if uuid_list and max(Counter(uuid_list).values()) > 1:
raise serializers.ValidationError(
{
Expand Down Expand Up @@ -655,6 +647,7 @@ def update_or_create_partij_identificator(self, partij_identificator):
partij_identificator_serializer.validated_data
)

@handle_db_exceptions
@transaction.atomic
def update(self, instance, validated_data):
method = self.context.get("request").method
Expand Down Expand Up @@ -831,6 +824,7 @@ def update(self, instance, validated_data):

return partij

@handle_db_exceptions
@transaction.atomic
def create(self, validated_data):
partij_identificatie = validated_data.pop("partij_identificatie", None)
Expand Down
Loading

0 comments on commit 7c0b655

Please sign in to comment.