本文整理汇总了Python中misago.threads.testutils.reply_thread函数的典型用法代码示例。如果您正苦于以下问题:Python reply_thread函数的具体用法?Python reply_thread怎么用?Python reply_thread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了reply_thread函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_category_prune_by_last_reply
def test_category_prune_by_last_reply(self):
"""command prunes category content based on last reply date"""
category = Category.objects.all_categories()[:1][0]
category.prune_replied_after = 20
category.save()
# post old threads with recent replies
started_on = timezone.now() - timedelta(days=30)
for t in range(10):
thread = testutils.post_thread(category, started_on=started_on)
testutils.reply_thread(thread)
# post recent threads that will be preserved
threads = [testutils.post_thread(category) for t in range(10)]
category.synchronize()
self.assertEqual(category.threads, 20)
self.assertEqual(category.posts, 30)
# run command
command = prunecategories.Command()
out = StringIO()
command.execute(stdout=out)
category.synchronize()
self.assertEqual(category.threads, 10)
self.assertEqual(category.posts, 10)
for thread in threads:
category.thread_set.get(id=thread.id)
command_output = out.getvalue().strip()
self.assertEqual(command_output, 'Categories were pruned')
示例2: test_filled_threads_list
def test_filled_threads_list(self):
"""filled threads list is rendered"""
forum = Forum.objects.all_forums().filter(role="forum")[:1][0]
threads = [testutils.post_thread(forum) for t in xrange(10)]
# only unread tracker threads are shown on unread list
response = self.client.get(reverse('misago:unread_threads'))
self.assertEqual(response.status_code, 200)
self.assertIn("There are no threads with unread", response.content)
# we'll read and reply to first five threads
for thread in threads[5:]:
response = self.client.get(thread.get_absolute_url())
testutils.reply_thread(thread, posted_on=timezone.now())
# assert that replied threads show on list
response = self.client.get(reverse('misago:unread_threads'))
self.assertEqual(response.status_code, 200)
for thread in threads[5:]:
self.assertIn(thread.get_absolute_url(), response.content)
for thread in threads[:5]:
self.assertNotIn(thread.get_absolute_url(), response.content)
# clear list
response = self.client.post(reverse('misago:clear_unread_threads'))
self.assertEqual(response.status_code, 302)
response = self.client.get(response['location'])
self.assertEqual(response.status_code, 200)
self.assertIn("There are no threads with unread", response.content)
示例3: setUp
def setUp(self):
super(ThreadPostSplitApiTestCase, self).setUp()
self.category = Category.objects.get(slug='first-category')
self.thread = testutils.post_thread(category=self.category)
self.posts = [
testutils.reply_thread(self.thread).pk, testutils.reply_thread(self.thread).pk
]
self.api_link = reverse(
'misago:api:thread-post-split', kwargs={
'thread_pk': self.thread.pk,
}
)
Category(
name='Category B',
slug='category-b',
).insert_at(
self.category,
position='last-child',
save=True,
)
self.category_b = Category.objects.get(slug='category-b')
self.override_acl()
self.override_other_acl()
示例4: test_new
def test_new(self):
"""new returns link to first unread post"""
self.user.new_threads = MockThreadsCounter()
self.user.unread_threads = MockThreadsCounter()
post_link = goto.new(self.user, self.thread, self.thread.post_set)
last_link = goto.last(self.thread, self.thread.post_set)
self.assertEqual(post_link, last_link)
# add 18 posts to add extra page to thread, then read them
[reply_thread(self.thread) for p in xrange(18)]
threadstracker.read_thread(
self.user, self.thread, self.thread.last_post)
# add extra unread posts
first_unread = reply_thread(self.thread)
[reply_thread(self.thread) for p in xrange(30)]
new_link = goto.new(self.user, self.thread, self.thread.post_set)
post_link = goto.get_post_link(
50, self.thread.post_set, self.thread, first_unread)
self.assertEqual(new_link, post_link)
# read thread
threadstracker.read_thread(
self.user, self.thread, self.thread.last_post)
# assert new() points to last reply
post_link = goto.new(self.user, self.thread, self.thread.post_set)
last_link = goto.last(self.thread, self.thread.post_set)
self.assertEqual(post_link, last_link)
示例5: test_merge_posts
def test_merge_posts(self):
"""moderation allows for merging multiple posts into one"""
posts = []
for p in xrange(4):
posts.append(reply_thread(self.thread, poster=self.user))
for p in xrange(4):
posts.append(reply_thread(self.thread))
self.thread.synchronize()
self.assertEqual(self.thread.replies, 8)
test_acl = {
'can_merge_posts': 1
}
self.override_acl(test_acl)
response = self.client.get(self.thread.get_absolute_url())
self.assertEqual(response.status_code, 200)
self.assertIn("Merge posts into one", response.content)
self.override_acl(test_acl)
response = self.client.post(self.thread.get_absolute_url(), data={
'action': 'merge', 'item': [p.pk for p in posts[:1]]
})
self.assertEqual(response.status_code, 200)
self.assertIn("select at least two posts", response.content)
thread = Thread.objects.get(pk=self.thread.pk)
self.assertEqual(thread.replies, 8)
self.override_acl(test_acl)
response = self.client.post(self.thread.get_absolute_url(), data={
'action': 'merge', 'item': [p.pk for p in posts[3:5]]
})
self.assertEqual(response.status_code, 200)
self.assertIn("merge posts made by different authors",
response.content)
thread = Thread.objects.get(pk=self.thread.pk)
self.assertEqual(thread.replies, 8)
self.override_acl(test_acl)
response = self.client.post(self.thread.get_absolute_url(), data={
'action': 'merge', 'item': [p.pk for p in posts[5:7]]
})
self.assertEqual(response.status_code, 200)
self.assertIn("merge posts made by different authors",
response.content)
thread = Thread.objects.get(pk=self.thread.pk)
self.assertEqual(thread.replies, 8)
self.override_acl(test_acl)
response = self.client.post(self.thread.get_absolute_url(), data={
'action': 'merge', 'item': [p.pk for p in posts[:4]]
})
self.assertEqual(response.status_code, 302)
thread = Thread.objects.get(pk=self.thread.pk)
self.assertEqual(thread.replies, 5)
示例6: test_move_posts
def test_move_posts(self):
"""api moves posts to other thread"""
self.override_other_acl({'can_reply_threads': 1})
other_thread = testutils.post_thread(self.category_b)
posts = (
testutils.reply_thread(self.thread).pk, testutils.reply_thread(self.thread).pk,
testutils.reply_thread(self.thread).pk, testutils.reply_thread(self.thread).pk,
)
self.refresh_thread()
self.assertEqual(self.thread.replies, 4)
response = self.client.post(
self.api_link,
json.dumps({
'thread_url': other_thread.get_absolute_url(),
'posts': posts,
}),
content_type="application/json",
)
self.assertEqual(response.status_code, 200)
# replies were moved
self.refresh_thread()
self.assertEqual(self.thread.replies, 0)
other_thread = Thread.objects.get(pk=other_thread.pk)
self.assertEqual(other_thread.post_set.filter(pk__in=posts).count(), 4)
self.assertEqual(other_thread.replies, 4)
示例7: test_approve_posts
def test_approve_posts(self):
"""moderation allows for approving multiple posts"""
posts = []
for p in xrange(4):
posts.append(reply_thread(self.thread, is_moderated=True))
for p in xrange(4):
posts.append(reply_thread(self.thread))
self.assertTrue(self.reload_thread().has_moderated_posts)
self.assertEqual(self.thread.replies, 4)
test_acl = {
'can_review_moderated_content': 1
}
self.override_acl(test_acl)
response = self.client.get(self.thread.get_absolute_url())
self.assertEqual(response.status_code, 200)
self.assertIn("Approve posts", response.content)
self.override_acl(test_acl)
response = self.client.post(self.thread.get_absolute_url(), data={
'action': 'approve', 'item': [p.pk for p in posts]
})
self.assertEqual(response.status_code, 302)
self.assertFalse(self.reload_thread().has_moderated_posts)
self.assertEqual(self.reload_thread().replies, 8)
for post in posts:
self.assertFalse(self.thread.post_set.get(id=post.id).is_moderated)
示例8: test_forum_prune_by_last_reply
def test_forum_prune_by_last_reply(self):
"""command prunes forum content based on last reply date"""
forum = Forum.objects.all_forums().filter(role="forum")[:1][0]
forum.prune_replied_after = 20
forum.save()
# post old threads with recent replies
started_on = timezone.now() - timedelta(days=30)
for t in xrange(10):
thread = testutils.post_thread(forum, started_on=started_on)
testutils.reply_thread(thread)
# post recent threads that will be preserved
threads = [testutils.post_thread(forum) for t in xrange(10)]
forum.synchronize()
self.assertEqual(forum.threads, 20)
self.assertEqual(forum.posts, 30)
# run command
command = pruneforums.Command()
out = StringIO()
command.execute(stdout=out)
forum.synchronize()
self.assertEqual(forum.threads, 10)
self.assertEqual(forum.posts, 10)
for thread in threads:
forum.thread_set.get(id=thread.id)
command_output = out.getvalue().strip()
self.assertEqual(command_output, 'Forums were pruned')
示例9: test_middleware_counts_unread_thread
def test_middleware_counts_unread_thread(self):
"""middleware counts thread with unread reply, post read flags user for recount"""
self.user.sync_unread_private_threads = True
self.user.save()
self.client.post(self.thread.last_post.get_read_api_url())
# post read zeroed list of unread private threads
self.reload_user()
self.assertFalse(self.user.sync_unread_private_threads)
self.assertEqual(self.user.unread_private_threads, 0)
# reply to thread
testutils.reply_thread(self.thread)
self.user.sync_unread_private_threads = True
self.user.save()
# middleware did recount and accounted for new unread post
response = self.client.get('/')
self.assertEqual(response.status_code, 200)
self.reload_user()
self.assertFalse(self.user.sync_unread_private_threads)
self.assertEqual(self.user.unread_private_threads, 1)
示例10: test_delete_posts
def test_delete_posts(self):
"""moderation allows for deleting posts"""
posts = [reply_thread(self.thread) for t in xrange(10)]
self.thread.synchronize()
self.assertEqual(self.thread.replies, 10)
test_acl = {
'can_hide_posts': 2
}
self.override_acl(test_acl)
response = self.client.get(self.thread.get_absolute_url())
self.assertEqual(response.status_code, 200)
self.assertIn("Delete posts", response.content)
self.override_acl(test_acl)
response = self.client.post(self.thread.get_absolute_url(), data={
'action': 'delete', 'item': [p.pk for p in posts]
})
self.assertEqual(response.status_code, 302)
self.assertTrue(
response['location'].endswith(self.thread.get_absolute_url()))
thread = Thread.objects.get(pk=self.thread.pk)
self.assertEqual(thread.replies, 0)
posts = [reply_thread(self.thread) for t in xrange(30)]
second_page_link = reverse('misago:thread', kwargs={
'thread_id': self.thread.id,
'thread_slug': self.thread.slug,
'page': 2
})
self.override_acl(test_acl)
response = self.client.post(second_page_link, data={
'action': 'delete', 'item': [p.pk for p in posts[10:20]]
})
self.assertEqual(response.status_code, 302)
self.assertTrue(response['location'].endswith(second_page_link))
thread = Thread.objects.get(pk=self.thread.pk)
self.assertEqual(thread.replies, 20)
self.override_acl(test_acl)
response = self.client.post(second_page_link, data={
'action': 'delete', 'item': [p.pk for p in posts[:-10]]
})
self.assertEqual(response.status_code, 302)
self.assertTrue(
response['location'].endswith(self.thread.get_absolute_url()))
thread = Thread.objects.get(pk=self.thread.pk)
self.assertEqual(thread.replies, 10)
示例11: test_moderated_list
def test_moderated_list(self):
"""moderated posts list works"""
self.override_acl({'can_review_moderated_content': True})
response = self.client.get(self.thread.get_moderated_url(),
**self.ajax_header)
self.assertEqual(response.status_code, 200)
self.assertIn("0 unapproved posts", response.content)
self.assertIn("There are no posts to display on this list.",
response.content)
# post 10 not moderated posts
[reply_thread(self.thread) for i in xrange(10)]
# assert that posts don't show
self.override_acl({'can_review_moderated_content': True})
response = self.client.get(self.thread.get_moderated_url(),
**self.ajax_header)
self.assertEqual(response.status_code, 200)
self.assertIn("0 unapproved posts", response.content)
self.assertIn("There are no posts to display on this list.",
response.content)
# post 10 reported posts
posts = []
for i in xrange(10):
posts.append(reply_thread(self.thread, is_moderated=True))
# assert that posts show
self.override_acl({'can_review_moderated_content': True})
response = self.client.get(self.thread.get_moderated_url(),
**self.ajax_header)
self.assertEqual(response.status_code, 200)
self.assertIn("10 unapproved posts", response.content)
self.assertNotIn("There are no posts to display on this list.",
response.content)
for post in posts:
self.assertIn(post.get_absolute_url(), response.content)
# overflow list via posting extra 20 reported posts
posts = []
for i in xrange(20):
posts.append(reply_thread(self.thread, is_moderated=True))
# assert that posts don't show
self.override_acl({'can_review_moderated_content': True})
response = self.client.get(self.thread.get_moderated_url(),
**self.ajax_header)
self.assertEqual(response.status_code, 200)
self.assertIn("30 unapproved posts", response.content)
self.assertIn("This list is limited to last 15 posts.",
response.content)
for post in posts[15:]:
self.assertIn(post.get_absolute_url(), response.content)
示例12: test_get_post_page
def test_get_post_page(self):
"""get_post_page returns valid page number for given queryset"""
self.assertEqual(goto.get_post_page(1, self.thread.post_set), 1)
# add 12 posts, bumping no of posts on page to to 13
[reply_thread(self.thread) for p in xrange(12)]
self.assertEqual(goto.get_post_page(13, self.thread.post_set), 1)
# add 2 posts
[reply_thread(self.thread) for p in xrange(2)]
self.assertEqual(goto.get_post_page(15, self.thread.post_set), 2)
示例13: test_get_post_page
def test_get_post_page(self):
"""get_post_page returns valid page number for given queryset"""
self.assertEqual(goto.get_post_page(1, self.thread.post_set), 1)
# fill out page
[reply_thread(self.thread) for p in xrange(MAX_PAGE_LEN - 1)]
self.assertEqual(
goto.get_post_page(MAX_PAGE_LEN, self.thread.post_set), 1)
# add 2 posts, adding second page
[reply_thread(self.thread) for p in xrange(2)]
self.assertEqual(
goto.get_post_page(MAX_PAGE_LEN + 2, self.thread.post_set), 2)
示例14: test_category_archive_by_start_date
def test_category_archive_by_start_date(self):
"""command archives category content based on start date"""
category = Category.objects.all_categories()[:1][0]
archive = Category.objects.create(
lft=7,
rght=8,
tree_id=2,
level=0,
name='Archive',
slug='archive',
)
category.prune_started_after = 20
category.archive_pruned_in = archive
category.save()
# post old threads with recent replies
started_on = timezone.now() - timedelta(days=30)
posted_on = timezone.now()
for t in range(10):
thread = testutils.post_thread(category, started_on=started_on)
testutils.reply_thread(thread, posted_on=posted_on)
# post recent threads that will be preserved
threads = [testutils.post_thread(category) for t in range(10)]
category.synchronize()
self.assertEqual(category.threads, 20)
self.assertEqual(category.posts, 30)
# run command
command = prunecategories.Command()
out = StringIO()
command.execute(stdout=out)
category.synchronize()
self.assertEqual(category.threads, 10)
self.assertEqual(category.posts, 10)
archive.synchronize()
self.assertEqual(archive.threads, 10)
self.assertEqual(archive.posts, 20)
for thread in threads:
category.thread_set.get(id=thread.id)
command_output = out.getvalue().strip()
self.assertEqual(command_output, 'Categories were pruned')
示例15: setUp
def setUp(self):
super(PostBulkDeleteApiTests, self).setUp()
self.posts = [
testutils.reply_thread(self.thread, poster=self.user),
testutils.reply_thread(self.thread),
testutils.reply_thread(self.thread, poster=self.user),
]
self.api_link = reverse(
'misago:api:thread-post-list',
kwargs={
'thread_pk': self.thread.pk,
}
)