Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
self.comment = utils.create_comment(user=self.user, topic=self.topic)
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)
self.comment = utils.create_comment(topic=self.topic)
self.user_comment = utils.create_comment(topic=self.topic, user=self.user)
self.poll = CommentPoll.objects.create(comment=self.comment, name='foo')
self.poll_multi = CommentPoll.objects.create(comment=self.comment, name='bar', choice_max=2)
b'%PDF-1.0\n1 0 obj<>endobj 2 0 obj<>endobj 3 0 obj<>endobj\nxref\n0 4\n0000000000 65535 f\n000000'
b'0010 00000 n\n0000000053 00000 n\n0000000102 00000 n\ntrailer<>\nstartxre'
b'f\n149\n%EOF\n')
file_name = 'foo.pdf'
file = SimpleUploadedFile(
file_name, pdf.read(), content_type='application/pdf')
response = self.client.post(
reverse('spirit:comment:file-upload-ajax'),
HTTP_X_REQUESTED_WITH='XMLHttpRequest',
data={'file': file})
res = json.loads(response.content.decode('utf-8'))
first_url = res['url']
utils.cache_clear()
file.seek(0)
response = self.client.post(
reverse('spirit:comment:file-upload-ajax'),
HTTP_X_REQUESTED_WITH='XMLHttpRequest',
data={'file': file})
res = json.loads(response.content.decode('utf-8'))
second_url = res['url']
self.assertNotEqual(first_url, second_url)
def setUp(self):
utils.cache_clear()
self.user = utils.create_user()
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)
self.comment = utils.create_comment(topic=self.topic)
def setUp(self):
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(self.category)
self.comment = utils.create_comment(topic=self.topic)
self.topic_notification = TopicNotification.objects.create(
user=self.user, topic=self.topic,
comment=self.comment, is_active=True,
action=COMMENT)
def setUp(self):
utils.cache_clear()
def setUp(self):
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(self.category)
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)
self.topic2 = utils.create_topic(category=self.category, user=self.user)
self.poll = TopicPoll.objects.create(topic=self.topic)
self.poll_other = TopicPoll.objects.create(topic=self.topic2)
self.poll_choice = TopicPollChoice.objects.create(poll=self.poll, description="op1")
self.poll_choice2 = TopicPollChoice.objects.create(poll=self.poll, description="op2")
self.poll_other_choice = TopicPollChoice.objects.create(poll=self.poll_other, description="op2")
self.poll_vote = TopicPollVote.objects.create(user=self.user, choice=self.poll_choice)
self.poll_other_vote = TopicPollVote.objects.create(user=self.user, choice=self.poll_other_choice)
"""
Should prevent double posts
"""
utils.login(self)
category_private = Category.objects.get(
pk=settings.ST_TOPIC_PRIVATE_CATEGORY_PK)
topic_title = 'title foobar'
# First post
self.client.post(
reverse('spirit:topic:private:publish'),
{'comment': 'foo', 'title': topic_title, 'users': [self.user2.username]})
self.assertEqual(len(Topic.objects.all()), 1)
# Double post
utils.cache_clear() # Clear rate limit
response = self.client.post(
reverse('spirit:topic:private:publish'),
{'comment': 'new foo', 'title': topic_title, 'users': [self.user2.username]})
self.assertEqual(len(Topic.objects.all()), 1) # Prevented!
self.assertRedirects(
response,
expected_url=category_private.get_absolute_url(),
status_code=302,
target_status_code=200)
# New post
utils.cache_clear() # Clear rate limit
self.client.post(
reverse('spirit:topic:private:publish'),
{'comment': 'foo', 'title': 'new topic', 'users': [self.user2.username]})