Apply review suggestions

This commit is contained in:
Antoine Bartuccio 2024-07-10 10:17:08 +02:00 committed by Bartuccio Antoine
parent a8918ebe86
commit 6240eff160
2 changed files with 10 additions and 3 deletions

View File

@ -390,7 +390,7 @@ class ForumMessage(models.Model):
) )
def is_deleted(self): def is_deleted(self):
if self.id is None: if self._state.adding:
return False return False
meta = self.metas.exclude(action="EDIT").order_by("-date").first() meta = self.metas.exclude(action="EDIT").order_by("-date").first()
if meta: if meta:

View File

@ -16,9 +16,10 @@
import pytest import pytest
from django.test import Client from django.test import Client
from django.urls import reverse from django.urls import reverse
from pytest_django.asserts import assertRedirects
from core.models import User from core.models import User
from forum.models import Forum, ForumTopic from forum.models import Forum, ForumMessage, ForumTopic
@pytest.mark.django_db @pytest.mark.django_db
@ -33,7 +34,13 @@ class TestTopicCreation:
} }
assert not ForumTopic.objects.filter(_title=payload["title"]).first() assert not ForumTopic.objects.filter(_title=payload["title"]).first()
response = client.post(reverse("forum:new_topic", args=str(forum.id)), payload) response = client.post(reverse("forum:new_topic", args=str(forum.id)), payload)
assert response.status_code == 302 assertRedirects(
response,
expected_url=reverse(
"forum:view_message", args=str(ForumMessage.objects.all().count())
), # Get the last created message id
target_status_code=302,
)
topic = ForumTopic.objects.filter(_title=payload["title"]).first() topic = ForumTopic.objects.filter(_title=payload["title"]).first()
assert topic assert topic
assert topic.last_message.message == payload["message"] assert topic.last_message.message == payload["message"]