Skip to content

Commit

Permalink
show link to documentation:category_update for superuser only in docu…
Browse files Browse the repository at this point in the history
…mentation:category_detail
  • Loading branch information
vincentporte committed Sep 24, 2024
1 parent 1878967 commit be70a86
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lacommunaute/documentation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def __str__(self):
def get_absolute_url(self):
return reverse("documentation:category_detail", kwargs={"pk": self.pk, "slug": self.slug})

def get_update_url(self):
return reverse("documentation:category_update", kwargs={"pk": self.pk, "slug": self.slug})


class Document(Publication):
category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name="documents")
Expand Down
14 changes: 13 additions & 1 deletion lacommunaute/documentation/tests/tests_category_detail_view.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest # noqa

from django.urls import reverse

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


Expand Down Expand Up @@ -32,3 +32,15 @@ def test_category_detail_view_with_tagged_documents(client, db, url, category, a
assert response.status_code == 200
content = parse_response_to_soup(response, selector="main", replace_img_src=True, replace_in_href=[category])
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_update_view(client, db, url, category, user, link_is_visible):
if user:
client.force_login(user())
response = client.get(url)
assert response.status_code == 200
assert bool(category.get_update_url() in response.content.decode()) == link_is_visible
4 changes: 4 additions & 0 deletions lacommunaute/documentation/tests/tests_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def test_get_absolute_url(self, db):
category = CategoryFactory()
assert category.get_absolute_url() == f"/documentation/{category.slug}-{category.pk}/"

def test_get_update_url(self, db):
category = CategoryFactory()
assert category.get_update_url() == f"/documentation/{category.slug}-{category.pk}/update/"


class TestDocument:
def test_slug(self, db):
Expand Down

0 comments on commit be70a86

Please sign in to comment.