From f6ee749f965c22436e408c24672198d0b3f3583e Mon Sep 17 00:00:00 2001 From: Floris272 Date: Mon, 6 Jan 2025 15:26:05 +0100 Subject: [PATCH] Change locatie admins & add PT locatie model test --- src/open_producten/locaties/admin/contact.py | 6 +- src/open_producten/locaties/admin/locatie.py | 2 +- .../locaties/admin/organisatie.py | 3 +- src/open_producten/locaties/models/contact.py | 2 +- .../locaties/serializers/locatie.py | 5 +- .../locaties/tests/api/test_contact.py | 3 - .../locaties/tests/test_contact.py | 2 +- .../tests/api/test_producttype.py | 100 ++++++++++++++++++ src/openapi.yaml | 1 - tmp/celery_worker_heartbeat | 0 tmp/celery_worker_ready | 0 11 files changed, 111 insertions(+), 13 deletions(-) create mode 100644 tmp/celery_worker_heartbeat create mode 100644 tmp/celery_worker_ready diff --git a/src/open_producten/locaties/admin/contact.py b/src/open_producten/locaties/admin/contact.py index 864b491..822e5db 100644 --- a/src/open_producten/locaties/admin/contact.py +++ b/src/open_producten/locaties/admin/contact.py @@ -5,9 +5,9 @@ @admin.register(Contact) class ContactAdmin(admin.ModelAdmin): - list_display = ("organisatie", "achternaam", "voornaam") - list_filter = ("organisatie",) - search_fields = ("voornaam", "achternaam") + list_display = ("__str__", "organisatie") + list_filter = ("organisatie", "organisatie__stad") + search_fields = ("voornaam", "achternaam", "organisatie__naam") def get_queryset(self, request): return super().get_queryset(request).select_related("organisatie") diff --git a/src/open_producten/locaties/admin/locatie.py b/src/open_producten/locaties/admin/locatie.py index 6804f72..0c6979c 100644 --- a/src/open_producten/locaties/admin/locatie.py +++ b/src/open_producten/locaties/admin/locatie.py @@ -7,4 +7,4 @@ class LocatieAdmin(admin.ModelAdmin): list_display = ("naam", "stad", "postcode", "straat", "huisnummer") list_filter = ("stad",) - search_fields = ("naam", "stad") + search_fields = ("naam", "stad", "postcode", "straat") diff --git a/src/open_producten/locaties/admin/organisatie.py b/src/open_producten/locaties/admin/organisatie.py index 4692bea..3dbdde3 100644 --- a/src/open_producten/locaties/admin/organisatie.py +++ b/src/open_producten/locaties/admin/organisatie.py @@ -8,8 +8,7 @@ class OrganisatieAdmin(admin.ModelAdmin): list_display = ("naam",) list_filter = ("stad",) - search_fields = ("naam",) - ordering = ("naam",) + search_fields = ("naam", "stad", "postcode", "straat") fieldsets = ( ( diff --git a/src/open_producten/locaties/models/contact.py b/src/open_producten/locaties/models/contact.py index 050125f..af178d3 100644 --- a/src/open_producten/locaties/models/contact.py +++ b/src/open_producten/locaties/models/contact.py @@ -52,7 +52,7 @@ class Meta: def __str__(self): if self.organisatie: - return f"{self.organisatie.naam}: {self.voornaam} {self.achternaam}" + return f"{self.voornaam} {self.achternaam} ({self.organisatie.naam})" return f"{self.voornaam} {self.achternaam}" def get_email(self): diff --git a/src/open_producten/locaties/serializers/locatie.py b/src/open_producten/locaties/serializers/locatie.py index 44d3808..3b41eec 100644 --- a/src/open_producten/locaties/serializers/locatie.py +++ b/src/open_producten/locaties/serializers/locatie.py @@ -20,7 +20,10 @@ class Meta: class ContactSerializer(serializers.ModelSerializer): organisatie = OrganisatieSerializer(read_only=True) organisatie_id = serializers.PrimaryKeyRelatedField( - queryset=Organisatie.objects.all(), source="organisatie", write_only=True + queryset=Organisatie.objects.all(), + source="organisatie", + write_only=True, + required=False, ) class Meta: diff --git a/src/open_producten/locaties/tests/api/test_contact.py b/src/open_producten/locaties/tests/api/test_contact.py index f9d6c33..c6649be 100644 --- a/src/open_producten/locaties/tests/api/test_contact.py +++ b/src/open_producten/locaties/tests/api/test_contact.py @@ -36,9 +36,6 @@ def test_required_fields(self): self.assertEqual( response.data, { - "organisatie_id": [ - ErrorDetail(string="Dit veld is vereist.", code="required") - ], "voornaam": [ ErrorDetail(string="Dit veld is vereist.", code="required") ], diff --git a/src/open_producten/locaties/tests/test_contact.py b/src/open_producten/locaties/tests/test_contact.py index f1490c7..f43ace9 100644 --- a/src/open_producten/locaties/tests/test_contact.py +++ b/src/open_producten/locaties/tests/test_contact.py @@ -13,7 +13,7 @@ def setUp(self): ) def test_contact_str(self): - self.assertEqual(str(self.contact), "Test Org: Bob de Vries") + self.assertEqual(str(self.contact), "Bob de Vries (Test Org)") self.contact.organisatie = None self.contact.save() diff --git a/src/open_producten/producttypen/tests/api/test_producttype.py b/src/open_producten/producttypen/tests/api/test_producttype.py index a8ec9ee..b4bc910 100644 --- a/src/open_producten/producttypen/tests/api/test_producttype.py +++ b/src/open_producten/producttypen/tests/api/test_producttype.py @@ -199,6 +199,106 @@ def test_create_product_type_with_duplicate_ids_returns_error(self): }, ) + def test_create_complete_product_type(self): + locatie = LocatieFactory.create() + organisatie = OrganisatieFactory.create() + contact = ContactFactory.create() + + data = self.data | { + "locatie_ids": [locatie.id], + "organisatie_ids": [organisatie.id], + "contact_ids": [contact.id], + } + response = self.client.post(self.path, data) + + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + self.assertEqual(ProductType.objects.count(), 1) + + product_type = ProductType.objects.first() + thema = product_type.themas.first() + + expected_data = { + "id": str(product_type.id), + "naam": product_type.naam, + "samenvatting": product_type.samenvatting, + "beschrijving": product_type.beschrijving, + "uniforme_product_naam": product_type.uniforme_product_naam.uri, + "vragen": [], + "prijzen": [], + "links": [], + "bestanden": [], + "locaties": [ + { + "id": str(locatie.id), + "naam": locatie.naam, + "email": locatie.email, + "telefoonnummer": locatie.telefoonnummer, + "straat": locatie.straat, + "huisnummer": locatie.huisnummer, + "postcode": locatie.postcode, + "stad": locatie.stad, + } + ], + "organisaties": [ + { + "id": str(organisatie.id), + "naam": organisatie.naam, + "email": organisatie.email, + "telefoonnummer": organisatie.telefoonnummer, + "straat": organisatie.straat, + "huisnummer": organisatie.huisnummer, + "postcode": organisatie.postcode, + "stad": organisatie.stad, + }, + { + "id": str(contact.organisatie.id), + "naam": contact.organisatie.naam, + "email": contact.organisatie.email, + "telefoonnummer": contact.organisatie.telefoonnummer, + "straat": contact.organisatie.straat, + "huisnummer": contact.organisatie.huisnummer, + "postcode": contact.organisatie.postcode, + "stad": contact.organisatie.stad, + }, + ], + "contacten": [ + { + "id": str(contact.id), + "voornaam": contact.voornaam, + "achternaam": contact.achternaam, + "email": contact.email, + "telefoonnummer": contact.telefoonnummer, + "rol": contact.rol, + "organisatie": { + "id": str(contact.organisatie.id), + "naam": contact.organisatie.naam, + "email": contact.organisatie.email, + "telefoonnummer": contact.organisatie.telefoonnummer, + "straat": contact.organisatie.straat, + "huisnummer": contact.organisatie.huisnummer, + "postcode": contact.organisatie.postcode, + "stad": contact.organisatie.stad, + }, + } + ], + "gepubliceerd": False, + "aanmaak_datum": product_type.aanmaak_datum.astimezone().isoformat(), + "update_datum": product_type.update_datum.astimezone().isoformat(), + "keywords": [], + "themas": [ + { + "id": str(thema.id), + "naam": thema.naam, + "gepubliceerd": True, + "aanmaak_datum": thema.aanmaak_datum.astimezone().isoformat(), + "update_datum": thema.update_datum.astimezone().isoformat(), + "beschrijving": thema.beschrijving, + "hoofd_thema": thema.hoofd_thema, + } + ], + } + self.assertEqual(response.data, expected_data) + def test_update_minimal_product_type(self): product_type = ProductTypeFactory.create() response = self.client.put(self.detail_path(product_type), self.data) diff --git a/src/openapi.yaml b/src/openapi.yaml index ec8c1c6..4761360 100644 --- a/src/openapi.yaml +++ b/src/openapi.yaml @@ -1364,7 +1364,6 @@ components: maxLength: 100 required: - achternaam - - organisatie_id - voornaam Link: type: object diff --git a/tmp/celery_worker_heartbeat b/tmp/celery_worker_heartbeat new file mode 100644 index 0000000..e69de29 diff --git a/tmp/celery_worker_ready b/tmp/celery_worker_ready new file mode 100644 index 0000000..e69de29