pedagogy: add script to remove all previous doubled comments

This commit is contained in:
2019-09-04 20:49:17 +02:00
parent ca042fe75e
commit a69f7b12b1
7 changed files with 215 additions and 124 deletions

View File

@ -25,6 +25,7 @@
from django.conf import settings
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.core.management import call_command
from core.models import User, Notification
@ -421,6 +422,50 @@ class UVCommentCreationAndDisplay(TestCase):
)
self.assertNotContains(response, text="Superbe UV")
def test_create_uv_comment_twice_fail(self):
# Checks that the has_user_already_commented method works proprely
self.assertFalse(self.uv.has_user_already_commented(self.bibou))
# Create a first comment
self.client.login(username="root", password="plop")
self.client.post(
reverse("pedagogy:uv_detail", kwargs={"uv_id": self.uv.id}),
create_uv_comment_template(self.bibou.id),
)
# Checks that the has_user_already_commented method works proprely
self.assertTrue(self.uv.has_user_already_commented(self.bibou))
# Create the second comment
comment = create_uv_comment_template(self.bibou.id)
comment["comment"] = "Twice"
response = self.client.post(
reverse("pedagogy:uv_detail", kwargs={"uv_id": self.uv.id}), comment
)
self.assertEquals(response.status_code, 200)
self.assertTrue(
UVComment.objects.filter(comment__contains="Superbe UV").exists()
)
self.assertFalse(UVComment.objects.filter(comment__contains="Twice").exists())
self.assertContains(
response,
_(
"You already posted a comment on this UV. If you want to comment again, please modify or delete your previous comment."
),
)
# Ensure that there is no crash when no uv or no author is given
self.client.post(
reverse("pedagogy:uv_detail", kwargs={"uv_id": self.uv.id}),
create_uv_comment_template(self.bibou.id, exclude_list=["uv"]),
)
self.assertEquals(response.status_code, 200)
self.client.post(
reverse("pedagogy:uv_detail", kwargs={"uv_id": self.uv.id}),
create_uv_comment_template(self.bibou.id, exclude_list=["author"]),
)
self.assertEquals(response.status_code, 200)
class UVCommentDeleteTest(TestCase):
"""