Skip to content

Commit

Permalink
add link to PartnerCreateView in PartnerListView for superuser
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Sep 23, 2024
1 parent db7be24 commit a0a4cb1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lacommunaute/partner/tests/tests_partner_listview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
11 changes: 11 additions & 0 deletions lacommunaute/templates/partner/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,15 @@ <h1 class="s-title-01__title h1">{% trans "Partners" %}</h1>
</div>
</div>
</section>
{% if user.is_superuser %}
<section class="s-section">
<div class="s-section__container container">
<div class="s-section__row row">
<div class="s-section__col col-12">
<a href="{% url 'partner:create' %}" aria-label="Ajouter un nouveau partenaire" role="button" class="btn btn-outline-primary">Ajouter un nouveau partenaire</a>
</div>
</div>
</div>
</section>
{% endif %}
{% endblock content %}

0 comments on commit a0a4cb1

Please sign in to comment.