From 4dd882ccbfffd995ba35af7949ec0dbda9bce1c9 Mon Sep 17 00:00:00 2001 From: vincent porte Date: Mon, 23 Sep 2024 12:19:57 +0200 Subject: [PATCH] add link to PartnerCreateView in PartnerListView for superuser --- .../partner/tests/tests_partner_listview.py | 13 +++++++++++++ lacommunaute/templates/partner/list.html | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/lacommunaute/partner/tests/tests_partner_listview.py b/lacommunaute/partner/tests/tests_partner_listview.py index 6d6ef5deb..f63633fa3 100644 --- a/lacommunaute/partner/tests/tests_partner_listview.py +++ b/lacommunaute/partner/tests/tests_partner_listview.py @@ -2,6 +2,7 @@ from django.urls import reverse from lacommunaute.partner.factories import PartnerFactory +from lacommunaute.users.factories import UserFactory from lacommunaute.utils.testing import parse_response_to_soup @@ -24,3 +25,15 @@ def test_pagination(client, db, snapshot, url): response = client.get(url) assert response.status_code == 200 assert str(parse_response_to_soup(response, selector="ul.pagination")) == snapshot(name="partner_pagination") + + +@pytest.mark.parametrize( + "user,link_is_visible", + [(None, False), (lambda: UserFactory(), False), (lambda: UserFactory(is_superuser=True), True)], +) +def test_link_to_createview(client, db, url, user, link_is_visible): + if user: + client.force_login(user()) + response = client.get(url) + assert response.status_code == 200 + assert bool(reverse("partner:create") in response.content.decode()) == link_is_visible diff --git a/lacommunaute/templates/partner/list.html b/lacommunaute/templates/partner/list.html index 547473bf3..680ae42ce 100644 --- a/lacommunaute/templates/partner/list.html +++ b/lacommunaute/templates/partner/list.html @@ -56,4 +56,15 @@

{% trans "Partners" %}

+ {% if user.is_superuser %} +
+ +
+ {% endif %} {% endblock content %}