Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
utils.login(self)
self.user.st.is_moderator = True
self.user.save()
category = utils.create_category()
topic = utils.create_topic(category)
form_data = {}
response = self.client.post(
reverse('spirit:topic:moderate:pin', kwargs={'pk': topic.pk, }),
form_data)
expected_url = topic.get_absolute_url()
self.assertRedirects(response, expected_url, status_code=302)
self.assertTrue(Topic.objects.get(pk=topic.pk).is_pinned)
self.assertEqual(
len(Comment.objects.filter(user=self.user, topic=topic, action=PINNED)),
1)
"""
utils.login(self)
self.user.st.is_moderator = True
self.user.save()
Topic.objects.filter(pk=self.topic.pk).update(comment_count=2)
comment = utils.create_comment(user=self.user, topic=self.topic)
comment2 = utils.create_comment(user=self.user, topic=self.topic)
to_topic = utils.create_topic(category=self.category)
form_data = {'topic': to_topic.pk,
'comments': [comment.pk, comment2.pk], }
response = self.client.post(reverse('spirit:comment:move', kwargs={'topic_id': self.topic.pk, }),
form_data)
expected_url = self.topic.get_absolute_url()
self.assertRedirects(response, expected_url, status_code=302)
self.assertEqual(Comment.objects.filter(topic=to_topic.pk).count(), 2)
self.assertEqual(Comment.objects.filter(topic=self.topic.pk).count(), 0)
self.assertEqual(Topic.objects.get(pk=self.topic.pk).comment_count, 0)
def test_comment_create_moderation_action(self):
"""
Create comment that tells what moderation action was made
"""
Comment.create_moderation_action(user=self.user, topic=self.topic, action=1)
self.assertEqual(Comment.objects.filter(user=self.user, topic=self.topic, action=1).count(), 1)
def test_comments_move(self):
comment = utils.create_comment(user=self.user, topic=self.topic)
comment2 = utils.create_comment(user=self.user, topic=self.topic)
to_topic = utils.create_topic(category=self.category)
form_data = {'topic': to_topic.pk,
'comments': [comment.pk, comment2.pk], }
form = CommentMoveForm(topic=self.topic, data=form_data)
self.assertEqual(form.is_valid(), True)
self.assertEqual(form.save(), list(Comment.objects.filter(topic=to_topic)))
def likes(request, pk, slug):
# todo: test with_polls!
user_comments = (
Comment.objects
.filter(comment_likes__user_id=pk)
.visible()
.with_polls(user=request.user)
.select_related('topic')
.order_by('-comment_likes__date', '-pk'))
return _activity(
request, pk, slug,
queryset=user_comments,
template='spirit/user/profile_likes.html',
reverse_to='spirit:user:likes',
context_name='comments',
per_page=config.comments_per_page)
def decrease_likes_count(self, acting_user):
Comment.objects\
.filter(pk=self.pk)\
.update(likes_count=F('likes_count') - 1)
if not self.topic.category.is_private:
self.user.st.decrease_received_likes_count()
acting_user.st.decrease_given_likes_count()
def delete(request, pk, remove=True):
comment = get_object_or_404(Comment, pk=pk)
if request.method == 'POST':
(Comment.objects
.filter(pk=pk)
.update(is_removed=remove))
return redirect(request.GET.get('next', comment.get_absolute_url()))
context = {'comment': comment}
return render(request, 'spirit/comment/moderate.html', context)