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):
if self.id is None:
if self._state.adding:
return False
meta = self.metas.exclude(action="EDIT").order_by("-date").first()
if meta:

View File

@ -16,9 +16,10 @@
import pytest
from django.test import Client
from django.urls import reverse
from pytest_django.asserts import assertRedirects
from core.models import User
from forum.models import Forum, ForumTopic
from forum.models import Forum, ForumMessage, ForumTopic
@pytest.mark.django_db
@ -33,7 +34,13 @@ class TestTopicCreation:
}
assert not ForumTopic.objects.filter(_title=payload["title"]).first()
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()
assert topic
assert topic.last_message.message == payload["message"]