• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python testutils.post_thread函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中misago.threads.testutils.post_thread函数的典型用法代码示例。如果您正苦于以下问题:Python post_thread函数的具体用法?Python post_thread怎么用?Python post_thread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了post_thread函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_moderated_threads_visibility

    def test_moderated_threads_visibility(self):
        """moderated threads are not rendered to non-moderator, except owned"""
        test_acl = {
            'can_see': 1,
            'can_browse': 1,
            'can_see_all_threads': 1,
            'can_review_moderated_content': 0,
        }

        test_title = "Test moderated thread"
        thread = testutils.post_thread(
            forum=self.forum, title=test_title, is_moderated=True)

        self.override_acl(test_acl)
        response = self.client.get(self.link)
        self.assertEqual(response.status_code, 200)
        self.assertNotIn(test_title, response.content)

        test_title = "Test owned moderated thread"
        thread = testutils.post_thread(
            forum=self.forum,
            title=test_title,
            is_moderated=True,
            poster=self.user)

        self.override_acl(test_acl)
        response = self.client.get(self.link)
        self.assertEqual(response.status_code, 200)
        self.assertIn(test_title, response.content)
开发者ID:hwy801207,项目名称:Misago,代码行数:29,代码来源:test_forumthreads_view.py


示例2: test_delete_category_and_contents

    def test_delete_category_and_contents(self):
        """category and its contents were deleted"""
        for _ in range(10):
            testutils.post_thread(self.category_b)

        response = self.client.get(
            reverse('misago:admin:categories:nodes:delete', kwargs={
                'pk': self.category_b.pk,
            })
        )
        self.assertEqual(response.status_code, 200)

        response = self.client.post(
            reverse('misago:admin:categories:nodes:delete', kwargs={
                'pk': self.category_b.pk,
            }),
            data={
                'move_children_to': '',
                'move_threads_to': '',
            }
        )
        self.assertEqual(response.status_code, 302)

        self.assertEqual(Category.objects.all_categories().count(), 4)
        self.assertEqual(Thread.objects.count(), 0)

        self.assertValidTree([
            (self.root, 0, 1, 10),
            (self.first_category, 1, 2, 3),
            (self.category_a, 1, 4, 5),
            (self.category_e, 1, 6, 9),
            (self.category_f, 2, 7, 8),
        ])
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:33,代码来源:test_categories_admin_views.py


示例3: 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')
开发者ID:l0ud,项目名称:Misago,代码行数:35,代码来源:test_prunecategories.py


示例4: test_thread_visibility

    def test_thread_visibility(self):
        """only participated threads are returned by private threads api"""
        visible = testutils.post_thread(category=self.category, poster=self.user)
        reported = testutils.post_thread(category=self.category, poster=self.user)

        # hidden thread
        testutils.post_thread(category=self.category, poster=self.user)

        ThreadParticipant.objects.add_participants(visible, [self.user])

        reported.has_reported_posts = True
        reported.save()

        response = self.client.get(self.api_link)
        self.assertEqual(response.status_code, 200)

        response_json = response.json()
        self.assertEqual(response_json['count'], 1)
        self.assertEqual(response_json['results'][0]['id'], visible.id)

        # threads with reported posts will also show to moderators
        override_acl(self.user, {'can_moderate_private_threads': 1})

        response = self.client.get(self.api_link)
        self.assertEqual(response.status_code, 200)

        response_json = response.json()
        self.assertEqual(response_json['count'], 2)
        self.assertEqual(response_json['results'][0]['id'], reported.id)
        self.assertEqual(response_json['results'][1]['id'], visible.id)
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:30,代码来源:test_privatethreads_api.py


示例5: 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')
开发者ID:Backenkoehler,项目名称:Misago,代码行数:35,代码来源:test_pruneforums.py


示例6: test_anonymous_request

    def test_anonymous_request(self):
        """view renders to anonymous users"""
        anon_title = "Hello Anon!"
        testutils.post_thread(forum=self.forum, title=anon_title)

        response = self.client.get(self.link)
        self.assertEqual(response.status_code, 200)
        self.assertIn(anon_title, response.content)
开发者ID:hwy801207,项目名称:Misago,代码行数:8,代码来源:test_forumthreads_view.py


示例7: test_user_with_no_threads

    def test_user_with_no_threads(self):
        """user with no private threads has 0 unread threads"""
        for i in range(5):
            # post 5 invisible threads
            testutils.post_thread(
                self.forum, started_on=timezone.now() - timedelta(days=2))

        sync_user_unread_private_threads_count(self.user)
        self.assertEqual(self.user.unread_private_threads, 0)
开发者ID:Backenkoehler,项目名称:Misago,代码行数:9,代码来源:test_counters.py


示例8: setUp

    def setUp(self):
        super(ThreadsBulkPatchApiTestCase, self).setUp()

        self.threads = list(reversed([
            testutils.post_thread(category=self.category),
            testutils.post_thread(category=self.category),
            testutils.post_thread(category=self.category),
        ]))

        self.ids = list(reversed([t.id for t in self.threads]))

        self.api_link = reverse('misago:api:thread-list')
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:12,代码来源:test_thread_bulkpatch_api.py


示例9: test_delete_threads

    def test_delete_threads(self):
        """moderation allows for deleting threads"""
        threads = [testutils.post_thread(self.forum) for t in xrange(10)]

        self.forum.synchronize()
        self.assertEqual(self.forum.threads, 10)

        test_acl = {
            'can_see': 1,
            'can_browse': 1,
            'can_see_all_threads': 1,
            'can_hide_threads': 2
        }

        self.override_acl(test_acl)
        response = self.client.get(self.link)
        self.assertEqual(response.status_code, 200)
        self.assertIn("Delete threads", response.content)

        self.override_acl(test_acl)
        response = self.client.post(self.link, data={
            'action': 'delete', 'item': [t.pk for t in threads]
        })
        self.assertEqual(response.status_code, 302)
        self.assertTrue(response['location'].endswith(self.link))

        forum = Forum.objects.get(pk=self.forum.pk)
        self.assertEqual(forum.threads, 0)

        threads = [testutils.post_thread(self.forum) for t in xrange(60)]

        second_page_link = reverse('misago:forum', kwargs={
            'forum_id': self.forum.id,
            'forum_slug': self.forum.slug,
            'page': 2
        })

        self.override_acl(test_acl)
        response = self.client.post(second_page_link, data={
            'action': 'delete', 'item': [t.pk for t in threads[20:40]]
        })
        self.assertEqual(response.status_code, 302)
        self.assertTrue(response['location'].endswith(second_page_link))

        forum = Forum.objects.get(pk=self.forum.pk)
        self.assertEqual(forum.threads, 40)

        self.override_acl(test_acl)
        response = self.client.post(second_page_link, data={
            'action': 'delete', 'item': [t.pk for t in threads[:-20]]
        })
        self.assertEqual(response.status_code, 302)
        self.assertTrue(response['location'].endswith(self.link))
开发者ID:Backenkoehler,项目名称:Misago,代码行数:53,代码来源:test_forumthreads_view.py


示例10: test_list_with_threads

    def test_list_with_threads(self):
        """list returns list of visible threads"""
        test_threads = [
            testutils.post_thread(
                forum=self.forum,
                title="Hello, I am thread",
                is_moderated=False,
                poster=self.user),
            testutils.post_thread(
                forum=self.forum,
                title="Hello, I am moderated thread",
                is_moderated=True,
                poster=self.user),
            testutils.post_thread(
                forum=self.forum,
                title="Hello, I am other user thread",
                is_moderated=False,
                poster="Bob"),
            testutils.post_thread(
                forum=self.forum,
                title="Hello, I am other user moderated thread",
                is_moderated=True,
                poster="Bob"),
        ]

        self.override_acl({
            'can_see_all_threads': False,
            'can_review_moderated_content': False
        })

        threads = ForumThreads(self.user, self.forum)
        self.assertEqual(threads.list(), [test_threads[1], test_threads[0]])

        self.override_acl({
            'can_see_all_threads': True,
            'can_review_moderated_content': False
        })

        threads = ForumThreads(self.user, self.forum)
        self.assertEqual(threads.list(),
                         [test_threads[2], test_threads[1], test_threads[0]])

        self.override_acl({
            'can_see_all_threads': True,
            'can_review_moderated_content': True
        })

        threads = ForumThreads(self.user, self.forum)
        test_threads.reverse()
        self.assertEqual(threads.list(), test_threads)

        self.assertTrue(threads.page)
        self.assertTrue(threads.paginator)
开发者ID:hwy801207,项目名称:Misago,代码行数:53,代码来源:test_forumthreads_view.py


示例11: test_user_with_new_thread

    def test_user_with_new_thread(self):
        """user has one new private thread"""
        for i in range(5):
            # post 5 invisible threads
            testutils.post_thread(
                self.forum, started_on=timezone.now() - timedelta(days=2))

        thread = testutils.post_thread(
            self.forum, started_on=timezone.now() - timedelta(days=2))
        thread.threadparticipant_set.create(user=self.user)

        sync_user_unread_private_threads_count(self.user)
        self.assertEqual(self.user.unread_private_threads, 1)
开发者ID:Backenkoehler,项目名称:Misago,代码行数:13,代码来源:test_counters.py


示例12: 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')
开发者ID:l0ud,项目名称:Misago,代码行数:49,代码来源:test_prunecategories.py


示例13: test_filled_list

    def test_filled_list(self):
        """filled list is served"""
        post_thread(self.forum, poster=self.user)
        self.user.posts = 1
        self.user.save()

        self.logout_user()

        response = self.client.get(self.link)
        self.assertEqual(response.status_code, 200)
        self.assertIn(self.user.username, response.content)

        response = self.client.get(self.link)
        self.assertEqual(response.status_code, 200)
        self.assertIn(self.user.username, response.content)
开发者ID:ZerGabriel,项目名称:Misago,代码行数:15,代码来源:test_users_api.py


示例14: test_threads_merge_conflict_delete_all

    def test_threads_merge_conflict_delete_all(self):
        """api deletes all polls when delete all choice is selected"""
        self.override_acl({'can_merge_threads': 1})

        self.override_other_acl({'can_merge_threads': 1})

        other_thread = testutils.post_thread(self.category_b)
        testutils.post_poll(self.thread, self.user)
        testutils.post_poll(other_thread, self.user)

        response = self.client.post(
            self.api_link, {
                'thread_url': other_thread.get_absolute_url(),
                'poll': 0,
            }
        )
        self.assertContains(response, other_thread.get_absolute_url(), status_code=200)

        # other thread has two posts now
        self.assertEqual(other_thread.post_set.count(), 3)

        # first thread is gone
        with self.assertRaises(Thread.DoesNotExist):
            Thread.objects.get(pk=self.thread.pk)

        # polls and votes are gone
        self.assertEqual(Poll.objects.count(), 0)
        self.assertEqual(PollVote.objects.count(), 0)
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:28,代码来源:test_thread_merge_api.py


示例15: test_threads_merge_conflict_keep_other_poll

    def test_threads_merge_conflict_keep_other_poll(self):
        """api deletes first poll on merge"""
        self.override_acl({'can_merge_threads': 1})

        self.override_other_acl({'can_merge_threads': 1})

        other_thread = testutils.post_thread(self.category_b)
        poll = testutils.post_poll(self.thread, self.user)
        other_poll = testutils.post_poll(other_thread, self.user)

        response = self.client.post(
            self.api_link, {
                'thread_url': other_thread.get_absolute_url(),
                'poll': other_poll.pk,
            }
        )
        self.assertContains(response, other_thread.get_absolute_url(), status_code=200)

        # other thread has two posts now
        self.assertEqual(other_thread.post_set.count(), 3)

        # first thread is gone
        with self.assertRaises(Thread.DoesNotExist):
            Thread.objects.get(pk=self.thread.pk)

        # other poll and its votes are gone
        self.assertEqual(Poll.objects.filter(thread=self.thread).count(), 0)
        self.assertEqual(PollVote.objects.filter(thread=self.thread).count(), 0)

        self.assertEqual(Poll.objects.filter(thread=other_thread).count(), 1)
        self.assertEqual(PollVote.objects.filter(thread=other_thread).count(), 4)

        Poll.objects.get(pk=other_poll.pk)
        with self.assertRaises(Poll.DoesNotExist):
            Poll.objects.get(pk=poll.pk)
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:35,代码来源:test_thread_merge_api.py


示例16: test_merge_threads_moved_poll

    def test_merge_threads_moved_poll(self):
        """api merges two threads successfully, moving poll from other thread"""
        self.override_acl({'can_merge_threads': 1})

        self.override_other_acl({'can_merge_threads': 1})

        other_thread = testutils.post_thread(self.category_b)
        poll = testutils.post_poll(self.thread, self.user)

        response = self.client.post(
            self.api_link, {
                'thread_url': other_thread.get_absolute_url(),
            }
        )
        self.assertContains(response, other_thread.get_absolute_url(), status_code=200)

        # other thread has two posts now
        self.assertEqual(other_thread.post_set.count(), 3)

        # first thread is gone
        with self.assertRaises(Thread.DoesNotExist):
            Thread.objects.get(pk=self.thread.pk)

        # poll and its votes were moved
        self.assertEqual(Poll.objects.filter(pk=poll.pk, thread=other_thread).count(), 1)
        self.assertEqual(PollVote.objects.filter(poll=poll, thread=other_thread).count(), 4)
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:26,代码来源:test_thread_merge_api.py


示例17: test_threads_merge_conflict

    def test_threads_merge_conflict(self):
        """api errors on merge conflict, returning list of available polls"""
        self.override_acl({'can_merge_threads': 1})

        self.override_other_acl({'can_merge_threads': 1})

        other_thread = testutils.post_thread(self.category_b)
        poll = testutils.post_poll(self.thread, self.user)
        other_poll = testutils.post_poll(other_thread, self.user)

        response = self.client.post(
            self.api_link, {
                'thread_url': other_thread.get_absolute_url(),
            }
        )
        self.assertEqual(response.status_code, 400)
        self.assertEqual(
            response.json(), {
                'polls': [
                    [0, "Delete all polls"],
                    [poll.pk, poll.question],
                    [other_poll.pk, other_poll.question],
                ]
            }
        )

        # polls and votes were untouched
        self.assertEqual(Poll.objects.count(), 2)
        self.assertEqual(PollVote.objects.count(), 8)
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:29,代码来源:test_thread_merge_api.py


示例18: 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)
开发者ID:Backenkoehler,项目名称:Misago,代码行数:30,代码来源:test_unreadthreads_view.py


示例19: test_thread_is_closed

    def test_thread_is_closed(self):
        """api validates if thread is open"""
        self.override_acl({'can_merge_threads': 1})

        self.override_other_acl({
            'can_merge_threads': 1,
            'can_reply_threads': 0,
            'can_close_threads': 0,
        })

        other_thread = testutils.post_thread(self.category_b)

        self.thread.is_closed = True
        self.thread.save()

        response = self.client.post(
            self.api_link, {
                'thread_url': other_thread.get_absolute_url(),
            }
        )
        self.assertContains(
            response,
            "This thread is closed. You can't merge it with other threads.",
            status_code=403,
        )
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:25,代码来源:test_thread_merge_api.py


示例20: test_delete_expired_thread

    def test_delete_expired_thread(self):
        """test deletes one expired thread tracker, but spares the other"""
        thread = testutils.post_thread(self.category)

        existing = ThreadRead.objects.create(
            user=self.user_a,
            category=self.category,
            thread=thread,
            last_read_on=timezone.now() - timedelta(days=settings.MISAGO_READTRACKER_CUTOFF / 4)
        )

        deleted = ThreadRead.objects.create(
            user=self.user_b,
            category=self.category,
            thread=thread,
            last_read_on=timezone.now() - timedelta(days=settings.MISAGO_READTRACKER_CUTOFF * 2)
        )

        command = clearreadtracker.Command()

        out = StringIO()
        call_command(command, stdout=out)
        command_output = out.getvalue().strip()

        self.assertEqual(command_output, "Deleted 1 expired entries")

        ThreadRead.objects.get(pk=existing.pk)
        with self.assertRaises(ThreadRead.DoesNotExist):
            ThreadRead.objects.get(pk=deleted.pk)
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:29,代码来源:test_clearreadtracker.py



注:本文中的misago.threads.testutils.post_thread函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python testutils.reply_thread函数代码示例发布时间:2022-05-27
下一篇:
Python models.Thread类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap