Skip to content

Commit

Permalink
show link to documentation:category_create for superuser only in docu…
Browse files Browse the repository at this point in the history
…mentation:list
  • Loading branch information
vincentporte committed Sep 24, 2024
1 parent 1d35717 commit de8782f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lacommunaute/documentation/tests/tests_category_list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from lacommunaute.documentation.factories import CategoryFactory
from lacommunaute.utils.testing import parse_response_to_soup
from lacommunaute.users.factories import UserFactory


@pytest.fixture(name="url")
Expand Down Expand Up @@ -30,3 +31,15 @@ def test_category_list_view(client, db, url, objects, status_code, snapshot_name
assert response.status_code == status_code
content = parse_response_to_soup(response, selector="main", replace_img_src=True, replace_in_href=categories)
assert str(content) == snapshot(name=snapshot_name)


@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("documentation:category_create") in response.content.decode()) == link_is_visible
2 changes: 1 addition & 1 deletion lacommunaute/templates/documentation/category_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h2 class="mt-3">
<div class="s-section__container container">
<div class="s-section__row row">
<div class="col-12">
<a href="#" aria-label="Ajouter une catégorie documentaire" role="button" class="btn btn-outline-primary">Ajouter une catégorie documentaire</a>
<a href="{% url 'documentation:category_create' %}" aria-label="Ajouter une catégorie documentaire" role="button" class="btn btn-outline-primary">Ajouter une catégorie documentaire</a>
</div>
</div>
</div>
Expand Down

0 comments on commit de8782f

Please sign in to comment.