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 %}