From 4a639a5b3565f939fb3c94b64f0aae3655c4b692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Freitag?= Date: Tue, 17 Dec 2024 11:14:20 +0100 Subject: [PATCH 1/2] Test users admin memberships --- tests/users/test_admin.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/users/test_admin.py b/tests/users/test_admin.py index 7fefd32024..2a7c7fcbf6 100644 --- a/tests/users/test_admin.py +++ b/tests/users/test_admin.py @@ -1,5 +1,11 @@ +import pytest +from django.urls import reverse + from itou.users import admin from itou.users.models import JobSeekerProfile, User +from tests.companies.factories import CompanyMembershipFactory +from tests.institutions.factories import InstitutionMembershipFactory +from tests.prescribers.factories import PrescriberMembershipFactory from tests.users.factories import JobSeekerFactory @@ -108,3 +114,17 @@ def test_get_fields_to_transfer_for_job_seekers(): # - either an existing relation has been dropped (and the relation can be removed from the relevant list) assert not fields_to_transfer & fields_to_ignore, fields_to_transfer & fields_to_ignore assert {f.name for f in relation_fields} == fields_to_transfer | fields_to_ignore + + +@pytest.mark.parametrize( + "membership_factory", + [ + PrescriberMembershipFactory, + CompanyMembershipFactory, + InstitutionMembershipFactory, + ], +) +def test_admin_membership(admin_client, membership_factory): + membership = membership_factory() + response = admin_client.get(reverse("admin:users_user_change", args=(membership.user_id,))) + assert response.status_code == 200 From 0549366c0e42d260490dc385ab169ba02300a1ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Freitag?= Date: Tue, 17 Dec 2024 10:35:16 +0100 Subject: [PATCH 2/2] Use clearer labels for structure membership Following cf47b6641c5b6c3da10cab47ebb7cefcb360bc86, use the helper for more memberships. --- itou/approvals/admin.py | 4 ++-- itou/users/admin.py | 8 ++++---- itou/utils/admin.py | 16 +++++++++------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/itou/approvals/admin.py b/itou/approvals/admin.py index aece915d28..9e63c628d7 100644 --- a/itou/approvals/admin.py +++ b/itou/approvals/admin.py @@ -20,7 +20,7 @@ ItouTabularInline, PkSupportRemarkInline, get_admin_view_link, - get_company_view_link, + get_structure_view_link, ) from itou.utils.templatetags.str_filters import pluralizefr @@ -60,7 +60,7 @@ def has_add_permission(self, request, obj=None): @admin.display(description="Entreprise destinataire") def to_company_link(self, obj): - return get_company_view_link(obj.to_company) + return get_structure_view_link(obj.to_company, display_attr="display_name") # Custom read-only fields as workaround : # there is no direct relation between approvals and employee records diff --git a/itou/users/admin.py b/itou/users/admin.py index 3f096bd6bd..3d5d77e8fa 100644 --- a/itou/users/admin.py +++ b/itou/users/admin.py @@ -37,7 +37,7 @@ PkSupportRemarkInline, add_support_remark_to_obj, get_admin_view_link, - get_company_view_link, + get_structure_view_link, ) @@ -106,7 +106,7 @@ def has_add_permission(self, request, obj=None): @admin.display(description="Entreprise") def company_siret_link(self, obj): - return get_company_view_link(obj.company) + return get_structure_view_link(obj.company) class PrescriberMembershipInline(DisabledNotificationsMixin, ItouTabularInline): @@ -134,7 +134,7 @@ def has_add_permission(self, request, obj=None): return True def organization_id_link(self, obj): - return get_admin_view_link(obj.organization) + return get_structure_view_link(obj.organization) class InstitutionMembershipInline(ItouTabularInline): @@ -165,7 +165,7 @@ def has_add_permission(self, request, obj=None): return True def institution_id_link(self, obj): - return get_admin_view_link(obj.institution) + return get_structure_view_link(obj.institution) class JobApplicationInline(ItouTabularInline): diff --git a/itou/utils/admin.py b/itou/utils/admin.py index ba696825cf..678bd9faba 100644 --- a/itou/utils/admin.py +++ b/itou/utils/admin.py @@ -20,13 +20,15 @@ def get_admin_view_link(obj, *, content=None, view="change"): return format_html('{}', url, content or obj.pk) -def get_company_view_link(company): - return format_html( - "{} — SIRET : {} ({})", - get_admin_view_link(company, content=company.display_name), - company.siret, - company.kind, - ) +def get_structure_view_link(structure, display_attr="name"): + format_string = "{link}" + format_kwargs = {"link": get_admin_view_link(structure, content=getattr(structure, display_attr))} + if hasattr(structure, "siret"): + format_string += " — SIRET {siret}" + format_kwargs["siret"] = structure.siret + format_string += " ({kind})" + format_kwargs["kind"] = structure.kind + return format_html(format_string, **format_kwargs) class AbstractSupportRemarkInline(GenericStackedInline):