Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_form_increment_bookmark(self):
user = utils.create_user()
category = utils.create_category()
topic = utils.create_topic(category=category, user=user)
utils.create_comment(user=user, topic=topic)
CommentBookmark.objects.create(user=user, topic=topic)
# Update greater bookmark
page = 10
form_data = {'comment_number': config.comments_per_page * (page - 1) + 1}
form = BookmarkForm(user=user, topic=topic, data=form_data)
self.assertTrue(form.is_valid())
form.save()
number = CommentBookmark.objects.get(user=user, topic=topic).comment_number
self.assertTrue(number)
# Ignore lesser page
page = 1
form_data = {
'comment_number': CommentBookmark.page_to_comment_number(page)}
def test_comment_publish_same_post_into_another_topic(self):
"""
Should not prevent from posting the same comment into another topic
"""
utils.login(self)
topic_another = utils.create_topic(category=self.topic.category)
comment_txt = 'foobar'
self.client.post(
reverse('spirit:comment:publish', kwargs={'topic_id': self.topic.pk}),
{'comment': comment_txt})
self.assertEqual(len(Comment.objects.all()), 1)
utils.cache_clear() # Clear rate limit
self.client.post(
reverse('spirit:comment:publish', kwargs={'topic_id': topic_another.pk}),
{'comment': comment_txt})
self.assertEqual(len(Comment.objects.all()), 2)
def setUp(self):
utils.cache_clear()
self.user = utils.create_user()
self.user2 = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(self.category, user=self.user)
self.topic2 = utils.create_topic(self.category, user=self.user2)
def test_indexing_is_removed(self):
"""
Should set the removed flag when either\
topic, subcategory or category are removed
"""
main_category = utils.create_category()
category = utils.create_category(parent=main_category)
topic = utils.create_topic(category)
rebuild_index()
self.assertEqual(
len(self.topic_sqs.filter(is_removed=False)), 1)
topic.is_removed = True
topic.save()
rebuild_index()
self.assertEqual(
len(self.topic_sqs.filter(is_removed=False)), 0)
category.is_removed = True
category.save()
topic.is_removed = False
topic.save()
rebuild_index()
def setUp(self):
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category, user=self.user)
def test_topic_publish(self):
"""
create topic
"""
category = utils.create_category()
subcategory = utils.create_subcategory(category)
form_data = {'comment': 'foo', 'title': 'foobar',
'category': subcategory.pk}
form = TopicForm(self.user, data=form_data)
self.assertEqual(form.is_valid(), True)
def test_comment_increase_modified_count(self):
"""
Increase modified_count
"""
comment = utils.create_comment(topic=self.topic)
comment.increase_modified_count()
self.assertEqual(Comment.objects.get(pk=comment.pk).modified_count, 1)
def setUp(self):
utils.cache_clear()
self.user = utils.create_user()
self.user2 = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(self.category)
self.topic2 = utils.create_topic(self.category, user=self.user)
self.topic_unread = TopicUnread.objects.create(
user=self.user, topic=self.topic)
self.topic_unread2 = TopicUnread.objects.create(
user=self.user, topic=self.topic2)
self.topic_unread3 = TopicUnread.objects.create(
user=self.user2, topic=self.topic)
def test_like_delete_comment_decrease_likes_count(self):
"""
Should decrease the comment's likes_count
"""
utils.login(self)
comment = utils.create_comment(topic=self.topic, likes_count=1)
like = CommentLike.objects.create(user=self.user, comment=comment)
form_data = {}
response = self.client.post(reverse('spirit:comment:like:delete', kwargs={'pk': like.pk, }),
form_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Comment.objects.get(pk=comment.pk).likes_count, 0)