Skip to content

Commit

Permalink
fix zestedesavoir#4193 and test it
Browse files Browse the repository at this point in the history
  • Loading branch information
fdambrine committed Feb 24, 2018
1 parent a94f400 commit 0071f5d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
52 changes: 50 additions & 2 deletions zds/notification/tests/tests_tricky.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.test.utils import override_settings

from zds.forum.factories import CategoryFactory, ForumFactory
from zds.forum.models import Topic
from zds.forum.models import Topic, Post
from zds.gallery.factories import UserGalleryFactory
from zds.member.factories import StaffProfileFactory, ProfileFactory
from zds.notification.models import NewTopicSubscription, Notification, NewPublicationSubscription, \
Expand Down Expand Up @@ -46,14 +46,62 @@ def test_no_auto_ping(self):
{
'title': 'Super sujet',
'subtitle': 'Pour tester les notifs',
'text': "@{} is pinged, not @{}".format(self.user1.username, self.user2.username),
'text': '@{} is pinged, not @{}'.format(self.user1.username, self.user2.username),
'tags': ''
},
follow=False)
self.assertEqual(result.status_code, 302)
self.assertEqual(1, PingSubscription.objects.count(),
'As one user is pinged, only one subscription is created.')

def test_no_reping_on_edition(self):
"""
to be more accurate : on edition, only ping **new** members
"""
overridden_zds_app['comment']['enable_pings'] = True
self.assertTrue(self.client.login(username=self.user2.username, password='hostel77'))
result = self.client.post(
reverse('topic-new') + '?forum={0}'.format(self.forum11.pk),
{
'title': 'Super sujet',
'subtitle': 'Pour tester les notifs',
'text': "@{} is pinged".format(self.user1.username),
'tags': ''
},
follow=False)
self.assertEqual(result.status_code, 302)
self.assertEqual(1, PingSubscription.objects.count(),
'As one user is pinged, only one subscription is created.')
self.assertEqual(1, Notification.objects.count())
user3 = ProfileFactory().user
post = Topic.objects.last().last_message()
result = self.client.post(
reverse('post-edit') + '?message={0}'.format(post.pk),
{
'title': 'Super sujet',
'subtitle': 'Pour tester les notifs',
'text': '@{} is pinged even twice @{}'.format(self.user1.username, self.user1.username),
'tags': ''
},
follow=False)
self.assertEqual(result.status_code, 302)
self.assertEqual(1, PingSubscription.objects.count(),
'No added subscription.')
self.assertEqual(1, Notification.objects.count())
result = self.client.post(
reverse('post-edit') + '?message={0}'.format(post.pk),
{
'title': 'Super sujet',
'subtitle': 'Pour tester les notifs',
'text': '@{} is pinged even twice @{} and add @{}'.format(self.user1.username,
self.user1.username, user3.username),
'tags': ''
},
follow=False)
self.assertEqual(result.status_code, 302)
self.assertEqual(2, PingSubscription.objects.count())
self.assertEqual(2, Notification.objects.count())

def test_no_dead_notif_on_moving(self):
NewTopicSubscription.objects.get_or_create_active(self.user1, self.forum11)
self.assertTrue(self.client.login(username=self.user2.username, password='hostel77'))
Expand Down
2 changes: 2 additions & 0 deletions zds/utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,13 @@ class Meta:
related_name='comments', blank=True, null=True)

def update_content(self, text):
_, old_metadata, _ = render_markdown(self.text)
html, metadata, messages = render_markdown(text)
self.text = text
self.text_html = html
self.save()
all_the_pings = list(filter(lambda user_name: user_name != self.author.username, metadata.get('ping', [])))
all_the_pings = list(set(all_the_pings) - set(metadata))
max_ping_count = settings.ZDS_APP['comment']['max_pings']
first_pings = all_the_pings[:max_ping_count]
for username in first_pings:
Expand Down

0 comments on commit 0071f5d

Please sign in to comment.