Skip to content

Commit

Permalink
[#229] fix partijen admin search (#266)
Browse files Browse the repository at this point in the history
* [#229] fix partijen admin search

---------

Co-authored-by: Sonny Bakker <[email protected]>
  • Loading branch information
SonnyBA and Sonny Bakker authored Oct 17, 2024
1 parent 6ef966d commit 2963f4c
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class PartijAdmin(admin.ModelAdmin):
VertegenwoordigdenInlineAdmin,
PartijIdentificatorInlineAdmin,
)
search_fields = ("partij",)
search_fields = ("nummer", "uuid", "voorkeurs_digitaal_adres__adres")
autocomplete_fields = ("voorkeurs_digitaal_adres",)
readonly_fields = ("uuid",)
fieldsets = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@ class Meta:


class OrganisatieFactory(factory.django.DjangoModelFactory):
partij = factory.SubFactory(PartijFactory)
partij = factory.SubFactory(PartijFactory, soort_partij=SoortPartij.organisatie)
naam = factory.Faker("word")

class Meta:
model = Organisatie


class PersoonFactory(factory.django.DjangoModelFactory):
partij = factory.SubFactory(PartijFactory)
partij = factory.SubFactory(PartijFactory, soort_partij=SoortPartij.persoon)
contactnaam_voorletters = ".".join(random.choices(string.ascii_uppercase, k=2))

class Meta:
model = Persoon


class ContactpersoonFactory(factory.django.DjangoModelFactory):
partij = factory.SubFactory(PartijFactory)
partij = factory.SubFactory(PartijFactory, soort_partij=SoortPartij.contactpersoon)
contactnaam_voorletters = ".".join(random.choices(string.ascii_uppercase, k=2))

class Meta:
Expand Down
Empty file.
87 changes: 87 additions & 0 deletions src/openklant/components/klantinteracties/tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from uuid import uuid4

from django.urls import reverse

from django_webtest import WebTest
from webtest import Form, TestResponse

from openklant.accounts.tests.factories import SuperUserFactory
from openklant.components.klantinteracties.models.tests.factories.digitaal_adres import (
DigitaalAdresFactory,
)
from openklant.components.klantinteracties.models.tests.factories.partijen import (
PersoonFactory,
)


class PartijAdminTests(WebTest):
def _login_user(self, username: str, password: str) -> None:
request = self.app.get(reverse("admin:login"))

form: Form = request.forms["login-form"]
form["auth-username"] = username
form["auth-password"] = password
redirect = form.submit()

self.assertRedirects(redirect, reverse("admin:index"))

def test_search(self):
nummer_persoon = PersoonFactory(
partij__nummer="123456789",
contactnaam_voornaam="Willem",
contactnaam_achternaam="Wever",
)

uuid = uuid4()
uuid_persoon = PersoonFactory(
partij__uuid=uuid,
contactnaam_voornaam="Henk",
contactnaam_achternaam="Broek",
)

digitaal_adres = DigitaalAdresFactory(adres="[email protected]")

digitaal_adres_persoon = PersoonFactory(
partij__voorkeurs_digitaal_adres=digitaal_adres,
contactnaam_voornaam="Sjaak",
contactnaam_achternaam="Willemse",
)

SuperUserFactory(username="admin", password="admin")

self._login_user(username="admin", password="admin")

admin_url = reverse("admin:klantinteracties_partij_changelist")

# Test a nummer search query
response: TestResponse = self.app.get(admin_url)
search_form = response.forms["changelist-search"]

search_form["q"] = nummer_persoon.partij.nummer
search_response = search_form.submit()

self.assertContains(search_response, nummer_persoon.get_full_name())
self.assertNotContains(search_response, uuid_persoon.get_full_name())
self.assertNotContains(search_response, digitaal_adres_persoon.get_full_name())

# Test a uuid search query
response: TestResponse = self.app.get(admin_url)
search_form = response.forms["changelist-search"]

search_form["q"] = str(uuid)
search_response = search_form.submit()

self.assertContains(search_response, uuid_persoon.get_full_name())
self.assertNotContains(search_response, nummer_persoon.get_full_name())
self.assertNotContains(search_response, digitaal_adres_persoon.get_full_name())

# Test a adres search query
response: TestResponse = self.app.get(admin_url)
search_form = response.forms["changelist-search"]

search_form["q"] = digitaal_adres.adres
search_response = search_form.submit()

self.assertContains(search_response, digitaal_adres_persoon.get_full_name())
self.assertNotContains(search_response, nummer_persoon.get_full_name())
self.assertNotContains(search_response, uuid_persoon.get_full_name())

0 comments on commit 2963f4c

Please sign in to comment.