Skip to content

Commit

Permalink
Affichage en LS : utilisation du bon objet et tests (#5684)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceFox authored and Situphen committed Jan 31, 2022
1 parent 854f1ec commit a91d572
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
2 changes: 1 addition & 1 deletion templates/forum/category/forum.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@


{% block new_btn %}
{% if user.can_write_now %}
{% if user.profile.can_write_now %}
<a href="{% url 'topic-new' %}?forum={{ forum.pk }}" class="new-btn ico-after more blue">
{% trans "Nouveau sujet" %}
</a>
Expand Down
2 changes: 1 addition & 1 deletion templates/forum/topic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@


{% block new_btn %}
{% if user.can_write_now %}
{% if user.profile.can_write_now %}
<a href="{% url 'topic-new' %}?forum={{ topic.forum.pk }}" class="new-btn ico-after more blue">
{% trans "Nouveau sujet" %}
</a>
Expand Down
8 changes: 4 additions & 4 deletions templates/misc/message_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ <h4 class="alert-box-title">Pas encore membre ?</h4>
<a href="{% url "register-member" %}" class="alert-box-btn">{% trans "Créer un compte" %}</a>
</p>
</div>
{% elif not user.can_write_now %}
<div class="alert-box ico-after ico-alert light">
{% trans "Vous êtes en lecture seule. Vous ne pouvez pas poster de messages." %}
</div>
{% elif not user.profile.can_write_now %}
<div class="alert-box ico-after ico-alert light">
{% trans "Vous êtes en lecture seule. Vous ne pouvez pas poster de messages." %}
</div>
{% elif topic.antispam or is_antispam %}
<div class="alert-box ico-after ico-alert light">
{% trans "Vous venez de poster. Merci de patienter au moins 15 minutes entre deux messages consécutifs afin de limiter le flood." %}
Expand Down
39 changes: 39 additions & 0 deletions zds/forum/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,45 @@ def test_frontend_alert_existence_other_pages(self):
template_response = self.client.get(topic.get_absolute_url() + "?page=2")
self.assertNotIn(expected, template_response.content.decode("utf-8"))

def test_frontend_topic_message_when_profile_readonly(self):
readonly_profile = ProfileFactory(can_write=False)
self.client.force_login(readonly_profile.user)

topic = TopicFactory(forum=self.forum11, author=readonly_profile.user)
PostFactory(topic=topic, author=readonly_profile.user, position=1)
PostFactory(topic=topic, author=self.user, position=2)

template_response = self.client.get(topic.get_absolute_url())
decoded_content = template_response.content.decode("utf-8")
self.assertNotIn("Nouveau sujet", decoded_content)
self.assertNotIn("Éditer le sujet", decoded_content)
self.assertIn("Vous êtes en lecture seule. Vous ne pouvez pas poster de messages.", decoded_content)

def test_frontend_topic_no_message_when_profile_can_write(self):
self.client.force_login(self.user2)

topic = TopicFactory(forum=self.forum11, author=self.user2)
PostFactory(topic=topic, author=self.user2, position=1)
PostFactory(topic=topic, author=self.user, position=2)

template_response = self.client.get(topic.get_absolute_url())
decoded_content = template_response.content.decode("utf-8")
self.assertIn("Nouveau sujet", decoded_content)
self.assertIn("Éditer le sujet", decoded_content)
self.assertNotIn("Vous êtes en lecture seule. Vous ne pouvez pas poster de messages.", decoded_content)

def test_frontend_no_create_topic_when_profile_readonly(self):
readonly_profile = ProfileFactory(can_write=False)
self.client.force_login(readonly_profile.user)

template_response = self.client.get(self.forum22.get_absolute_url())
self.assertNotIn("Nouveau sujet", template_response.content.decode("utf-8"))

def test_frontend_can_create_topic_when_profile_can_write(self):
self.client.force_login(self.user)
template_response = self.client.get(self.forum22.get_absolute_url())
self.assertIn("Nouveau sujet", template_response.content.decode("utf-8"))


class ForumGuestTests(TestCase):
def setUp(self):
Expand Down

0 comments on commit a91d572

Please sign in to comment.