Skip to content

Commit

Permalink
Change locatie admins & add PT locatie model test
Browse files Browse the repository at this point in the history
  • Loading branch information
Floris272 committed Jan 6, 2025
1 parent 26d1c0d commit f6ee749
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/open_producten/locaties/admin/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 1 addition & 1 deletion src/open_producten/locaties/admin/locatie.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
3 changes: 1 addition & 2 deletions src/open_producten/locaties/admin/organisatie.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
(
Expand Down
2 changes: 1 addition & 1 deletion src/open_producten/locaties/models/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion src/open_producten/locaties/serializers/locatie.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions src/open_producten/locaties/tests/api/test_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
],
Expand Down
2 changes: 1 addition & 1 deletion src/open_producten/locaties/tests/test_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
100 changes: 100 additions & 0 deletions src/open_producten/producttypen/tests/api/test_producttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,6 @@ components:
maxLength: 100
required:
- achternaam
- organisatie_id
- voornaam
Link:
type: object
Expand Down
Empty file added tmp/celery_worker_heartbeat
Empty file.
Empty file added tmp/celery_worker_ready
Empty file.

0 comments on commit f6ee749

Please sign in to comment.