Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/hotfix-v1.2b' into prod
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavi committed Nov 10, 2014
2 parents de8e15c + 463a68e commit 7ed7bc1
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 9 deletions.
2 changes: 1 addition & 1 deletion assets/scss/_all-supports.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@
font-size: 1.6rem;
}
.topic-subtitle {
height: 24px;
min-height: 24px;
line-height: 1.5em;
color: #777;
}
Expand Down
2 changes: 1 addition & 1 deletion zds/article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ def solve_alert(request):
alert = get_object_or_404(Alert, pk=request.POST['alert_pk'])
reaction = Reaction.objects.get(pk=alert.comment.id)

if request.POST["text"] != "":
if "text" in request.POST and request.POST["text"] != "":
bot = get_object_or_404(User, username=settings.ZDS_APP['member']['bot_account'])
msg = (u'Bonjour {0},\n\nVous recevez ce message car vous avez '
u'signalé le message de *{1}*, dans l\'article [{2}]({3}). '
Expand Down
67 changes: 66 additions & 1 deletion zds/forum/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def setUp(self):
password='hostel77')
self.assertEqual(log, True)

settings.ZDS_APP['member']['bot_account'] = ProfileFactory().user.username

def feed_rss_display(self):
"""Test each rss feed feed"""
response = self.client.get(reverse('post-feed-rss'), follow=False)
Expand Down Expand Up @@ -312,7 +314,7 @@ def test_quote_post(self):
self.assertEqual(result.status_code, 200)

def test_signal_post(self):
"""To test when a member quote anyone post."""
"""To test when a member signal a post."""
user1 = ProfileFactory().user
topic1 = TopicFactory(forum=self.forum11, author=self.user)
PostFactory(topic=topic1, author=self.user, position=1)
Expand All @@ -333,6 +335,69 @@ def test_signal_post(self):
self.assertEqual(Alert.objects.filter(author=self.user).count(), 1)
self.assertEqual(Alert.objects.get(author=self.user).text, u'Troll')

# and test that staff can solve but not user
alert = Alert.objects.get(comment=post2.pk)
# try as a normal user
result = self.client.post(
reverse('zds.forum.views.solve_alert'),
{
'alert_pk': alert.pk,
},
follow=False)
self.assertEqual(result.status_code, 403)
# login as staff
staff1 = StaffProfileFactory().user
self.assertEqual(
self.client.login(
username=staff1.username,
password='hostel77'),
True)
# try again as staff
result = self.client.post(
reverse('zds.forum.views.solve_alert'),
{
'alert_pk': alert.pk,
'text': u'Everything is Ok kid'
},
follow=False)
self.assertEqual(result.status_code, 302)
self.assertEqual(Alert.objects.all().count(), 0)

def test_signal_and_solve_alert_empty_message(self):
"""To test when a member signal a post and staff solve it."""
user1 = ProfileFactory().user
topic1 = TopicFactory(forum=self.forum11, author=self.user)
PostFactory(topic=topic1, author=self.user, position=1)
post2 = PostFactory(topic=topic1, author=user1, position=2)
PostFactory(topic=topic1, author=user1, position=3)

result = self.client.post(
reverse('zds.forum.views.edit_post') +
'?message={0}'.format(post2.pk),
{
'signal_text': u'Troll',
'signal_message': 'confirmer'
},
follow=False)

alert = Alert.objects.get(comment=post2.pk)
# login as staff
staff1 = StaffProfileFactory().user
self.assertEqual(
self.client.login(
username=staff1.username,
password='hostel77'),
True)
# try again as staff
result = self.client.post(
reverse('zds.forum.views.solve_alert'),
{
'alert_pk': alert.pk,
},
follow=False)
self.assertEqual(result.status_code, 302)
self.assertEqual(Alert.objects.all().count(), 0)

def test_like_post(self):
"""Test when a member like any post."""
user1 = ProfileFactory().user
Expand Down
4 changes: 2 additions & 2 deletions zds/forum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ def solve_alert(request):
alert = get_object_or_404(Alert, pk=request.POST["alert_pk"])
post = Post.objects.get(pk=alert.comment.id)

if request.POST["text"] != "":
bot = get_object_or_404(User, username=settings.BOT_ACCOUNT)
if "text" in request.POST and request.POST["text"] != "":
bot = get_object_or_404(User, username=settings.ZDS_APP['member']['bot_account'])
msg = \
(u'Bonjour {0},'
u'Vous recevez ce message car vous avez signalé le message de *{1}*, '
Expand Down
44 changes: 44 additions & 0 deletions zds/mp/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,50 @@ def test_fail_answer_with_no_right(self):
self.assertEqual(403, response.status_code)
self.assertEqual(2, PrivatePost.objects.all().count())

def test_unicode_title_answer(self):
"""To test unicode title."""

unicodeTopic = PrivateTopicFactory(author=self.profile1.user,
title=u'Title with accent àéè')
unicodeTopic.participants.add(self.profile2.user)
unicodePost = PrivatePostFactory(
privatetopic=unicodeTopic,
author=self.profile1.user,
position_in_topic=1)

response = self.client.post(
reverse('zds.mp.views.answer')
+ '?sujet=' + str(unicodeTopic.pk),
{
'text': 'answer',
'last_post': unicodePost.pk
},
follow=True
)
self.assertEqual(response.status_code, 200)

def test_unicode_subtitle_answer(self):
"""To test unicode subtitle."""

unicodeTopic = PrivateTopicFactory(author=self.profile1.user,
subtitle=u'Subtitle with accent àéè')
unicodeTopic.participants.add(self.profile2.user)
unicodePost = PrivatePostFactory(
privatetopic=unicodeTopic,
author=self.profile1.user,
position_in_topic=1)

response = self.client.post(
reverse('zds.mp.views.answer')
+ '?sujet=' + str(unicodeTopic.pk),
{
'text': 'answer',
'last_post': unicodePost.pk
},
follow=True
)
self.assertEqual(response.status_code, 200)


class EditPostViewTest(TestCase):

Expand Down
6 changes: 3 additions & 3 deletions zds/mp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ def answer(request):
g_topic.save()

# send email
subject = "{} - MP : {}".format(settings.ZDS_APP['site']['abbr'], g_topic.title)
from_email = "{} <{}>".format(settings.ZDS_APP['site']['litteral_name'],
settings.ZDS_APP['site']['email_noreply'])
subject = u"{} - MP : {}".format(settings.ZDS_APP['site']['abbr'], g_topic.title)
from_email = u"{} <{}>".format(settings.ZDS_APP['site']['litteral_name'],
settings.ZDS_APP['site']['email_noreply'])
parts = list(g_topic.participants.all())
parts.append(g_topic.author)
parts.remove(request.user)
Expand Down
2 changes: 1 addition & 1 deletion zds/tutorial/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3308,7 +3308,7 @@ def solve_alert(request):
alert = get_object_or_404(Alert, pk=request.POST["alert_pk"])
note = Note.objects.get(pk=alert.comment.id)

if request.POST["text"] != "":
if "text" in request.POST and request.POST["text"] != "":
bot = get_object_or_404(User, username=settings.ZDS_APP['member']['bot_account'])
msg = \
(u'Bonjour {0},'
Expand Down

0 comments on commit 7ed7bc1

Please sign in to comment.