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_comment_update_moderator_private(self):
"""
moderators can not update comments in private topics they has no access
"""
UserProfile.objects.filter(user__pk=self.user.pk).update(is_moderator=True)
user = utils.create_user()
topic_private = utils.create_private_topic()
comment = utils.create_comment(user=user, topic=topic_private.topic)
utils.login(self)
form_data = {'comment': 'barfoo', }
response = self.client.post(reverse('spirit:comment:update', kwargs={'pk': comment.pk, }),
form_data)
self.assertEqual(response.status_code, 404)
def test_email_change_email_case_insensitive(self):
"""
Should lower case the email before validating it
"""
utils.create_user(email="duplicated@bar.com")
user = utils.create_user(password="foo")
form_data = {'email': 'DuPlIcAtEd@bAr.COM', 'password': 'foo'}
form = EmailChangeForm(data=form_data, user=user)
self.assertEqual(form.is_valid(), False)
def setUp(self):
utils.cache_clear()
self.user = utils.create_user()
self.category = Category.objects.get(pk=settings.ST_TOPIC_PRIVATE_CATEGORY_PK)
self.topic = utils.create_topic(category=self.category, user=self.user)
def setUp(self):
utils.cache_clear()
self.user = utils.create_user()
self.user2 = utils.create_user()
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.user2)
self.topic2 = utils.create_topic(self.category)
user = utils.create_user()
comment = utils.create_comment(user=user, topic=self.topic)
comment_posted(comment=comment, mentions=None)
self.assertEqual(len(TopicNotification.objects.all()), 2)
self.assertFalse(TopicNotification.objects.get(user=subscriber, topic=self.topic).is_read)
# Should notify mentions
mentioned = utils.create_user()
mentions = {mentioned.username: mentioned, }
comment = utils.create_comment(user=user, topic=self.topic)
comment_posted(comment=comment, mentions=mentions)
self.assertEqual(TopicNotification.objects.get(user=mentioned, comment=comment).action, MENTION)
self.assertFalse(TopicNotification.objects.get(user=mentioned, comment=comment).is_read)
# Should mark the topic as unread
user_unread = utils.create_user()
topic = utils.create_topic(self.category)
topic_unread_creator = TopicUnread.objects.create(user=user, topic=topic, is_read=True)
topic_unread_subscriber = TopicUnread.objects.create(user=user_unread, topic=topic, is_read=True)
comment = utils.create_comment(user=user, topic=topic)
comment_posted(comment=comment, mentions=None)
self.assertTrue(TopicUnread.objects.get(pk=topic_unread_creator.pk).is_read)
self.assertFalse(TopicUnread.objects.get(pk=topic_unread_subscriber.pk).is_read)
# Should increase topic's comment counter
topic = utils.create_topic(self.category)
comment = utils.create_comment(user=user, topic=topic)
comment_posted(comment=comment, mentions=None)
self.assertEqual(Topic.objects.get(pk=topic.pk).comment_count, 1)
comment_posted(comment=comment, mentions=None)
self.assertEqual(Topic.objects.get(pk=topic.pk).comment_count, 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_private_access_create_invalid(self):
"""
Only the topic owner should be able to invite
"""
utils.login(self)
private = utils.create_private_topic(user=self.user2)
TopicPrivate.objects.create(user=self.user, topic=private.topic)
user = utils.create_user()
form_data = {'user': user.username, }
response = self.client.post(reverse('spirit:topic:private:access-create', kwargs={'topic_id': private.topic.pk, }),
form_data)
self.assertEqual(response.status_code, 404)
def setUp(self):
utils.cache_clear()
self.user = utils.create_user()
self.category_1 = utils.create_category(title="cat1")
self.subcategory_1 = utils.create_subcategory(self.category_1)
self.category_2 = utils.create_category(title="cat2")
self.category_removed = utils.create_category(title="cat3", is_removed=True)
def test_poll_choice_increase_vote_count(self):
"""
Should increase the vote count of all choices for a given user and poll
"""
poll = CommentPoll.objects.create(comment=self.comment, name='percentage')
choice = CommentPollChoice.objects.create(poll=poll, number=1, description="foobar")
choice2 = CommentPollChoice.objects.create(poll=poll, number=2, description="foobar")
CommentPollVote.objects.create(choice=choice, voter=self.user)
CommentPollVote.objects.create(choice=choice2, voter=self.user)
user2 = utils.create_user()
CommentPollVote.objects.create(choice=choice, voter=user2)
CommentPollChoice.increase_vote_count(poll, self.user)
self.assertEqual(CommentPollChoice.objects.get(pk=self.choice.pk).vote_count, 0)
self.assertEqual(CommentPollChoice.objects.get(pk=choice.pk).vote_count, 1)
self.assertEqual(CommentPollChoice.objects.get(pk=choice2.pk).vote_count, 1)
CommentPollChoice.objects.filter(pk=choice.pk).update(is_removed=True)
CommentPollChoice.increase_vote_count(poll, self.user)
self.assertEqual(CommentPollChoice.objects.get(pk=choice.pk).vote_count, 1)
self.assertEqual(CommentPollChoice.objects.get(pk=choice2.pk).vote_count, 2)