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

Python models.Topic类代码示例

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

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



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

示例1: get_or_create_topic

    def get_or_create_topic(self, allow_post):
        if self._forum:
            topic = Topic(
                forum=self._forum,
                user=self.user,
                name=self.cleaned_data['name'],
            )

            if not allow_post:
                topic.on_moderation = topic.MODERATION_IS_IN_MODERATION
            topic.save()

            if not defaults.PYBB_DISABLE_POLLS:
                if 'poll_type' in self.cleaned_data and self.cleaned_data['poll_type'] != Poll.TYPE_NONE:
                    poll = Poll(
                        type=self.cleaned_data['poll_type'],
                        question=self.cleaned_data['poll_question']
                    )
                    poll.save()

                    topic.poll = poll
        else:
            topic = self._topic

        return topic
开发者ID:thoas,项目名称:pybbm,代码行数:25,代码来源:base.py


示例2: test_read_tracking_multi_forum

    def test_read_tracking_multi_forum(self):
        self.post

        topic_1 = self.topic
        topic_2 = Topic(name='topic_2', forum=self.forum, user=self.user)
        topic_2.save()

        Post(topic=topic_2, user=self.user, body='one').save()

        forum_2 = Forum(name='forum_2', description='bar', forum=self.parent_forum)
        forum_2.save()

        Topic(name='garbage', forum=forum_2, user=self.user).save()

        self.login_as(self.user)

        #  everything starts unread
        self.assertEqual(ForumReadTracker.objects.count(), 0)
        self.assertEqual(TopicReadTracker.objects.count(), 0)

        #  user reads topic_1, they should get one topic read tracker, there should be no forum read trackers
        self.client.get(topic_1.get_absolute_url())
        self.assertEqual(TopicReadTracker.objects.count(), 1)
        self.assertEqual(TopicReadTracker.objects.filter(user=self.user).count(), 1)
        self.assertEqual(TopicReadTracker.objects.filter(user=self.user, topic=topic_1).count(), 1)

        #  user reads topic_2, they should get a forum read tracker,
        #  there should be no topic read trackers for the user
        self.client.get(topic_2.get_absolute_url())
        self.assertEqual(TopicReadTracker.objects.count(), 0)
        self.assertEqual(ForumReadTracker.objects.count(), 1)
        self.assertEqual(ForumReadTracker.objects.filter(user=self.user).count(), 1)
        self.assertEqual(ForumReadTracker.objects.filter(user=self.user, forum=self.forum).count(), 1)
开发者ID:thoas,项目名称:pybbm,代码行数:33,代码来源:test_trackers.py


示例3: test_topic_move_complete

    def test_topic_move_complete(self):
        topic = Topic(name='xtopic', forum=self.forum, user=self.user)
        topic.save()
        post = Post(topic=topic, user=self.user, body='one')
        post.save()

        topic_merge_url = reverse('pybb:topic_move')

        self.login_as(self.staff)

        name = 'new name for a topic'

        response = self.client.post(topic_merge_url, data={
            'topic_ids': [topic.pk],
            'form-TOTAL_FORMS': 1,
            'form-INITIAL_FORMS': 0,
            'form-0-name': name,
            'form-0-forum': self.forum.pk,
            'form-0-redirection_type': TopicRedirection.TYPE_PERMANENT_REDIRECT,
            'submit': 1
        })

        self.assertRedirects(response, reverse('pybb:index'))

        topic = Topic.objects.get(pk=topic.pk)

        self.assertTrue(topic.redirect)
        self.failUnless(topic.redirection is not None)

        redirection = topic.redirection

        new_topic = redirection.to_topic

        self.assertEqual(new_topic.name, name)
        self.assertEqual(new_topic.post_count, 1)
开发者ID:thoas,项目名称:pybbm,代码行数:35,代码来源:test_features.py


示例4: save

 def save(self, commit=True):
     if self.instance.pk:
         post = super(PostForm, self).save(commit=False)
         if self.user:
             post.user = self.user
         if post.topic.head == post:
             post.topic.name = self.cleaned_data['name']
             post.topic.updated = datetime.now()
             post.topic.save()
         post.save()
         return post
     allow_post = True
     if defaults.PYBB_PREMODERATION:
             allow_post = defaults.PYBB_PREMODERATION(self.user, self.cleaned_data['body'])
     if self.forum:
         topic = Topic(forum=self.forum,
                       user=self.user,
                       name=self.cleaned_data['name'])
         if not allow_post:
             topic.on_moderation = True
         topic.save()
     else:
         topic = self.topic
     post = Post(topic=topic, user=self.user, user_ip=self.ip,
                 body=self.cleaned_data['body'])
     if not allow_post:
         post.on_moderation = True
     post.save()
     return post
开发者ID:makinacorpus,项目名称:pybbm,代码行数:29,代码来源:forms.py


示例5: test_forum_updated

 def test_forum_updated(self):
     time.sleep(1)
     topic = Topic(name='xtopic', forum=self.forum, user=self.user)
     topic.save()
     post = Post(topic=topic, user=self.user, body='one')
     post.save()
     post = Post.objects.get(id=post.id)
     self.assertTrue(self.forum.updated == post.created)
开发者ID:thoas,项目名称:pybbm,代码行数:8,代码来源:test_features.py


示例6: test_pagination_and_topic_addition

 def test_pagination_and_topic_addition(self):
     for i in range(0, defaults.PYBB_FORUM_PAGE_SIZE + 3):
         topic = Topic(name='topic_%s_' % i, forum=self.forum, user=self.user)
         topic.save()
     response = self.client.get(self.forum.get_absolute_url())
     self.assertEqual(len(response.context['topic_list']), defaults.PYBB_FORUM_PAGE_SIZE)
     self.assertTrue(response.context['is_paginated'])
     self.assertEqual(response.context['paginator'].num_pages,
                      (int((defaults.PYBB_FORUM_PAGE_SIZE + 3) / defaults.PYBB_FORUM_PAGE_SIZE) + 1))
开发者ID:thoas,项目名称:pybbm,代码行数:9,代码来源:test_features.py


示例7: test_compute_active_members

    def test_compute_active_members(self):
        # Initials
        self.assertEquals(self.parent_forum.member_count, 0)
        self.assertEquals(self.forum.member_count, 0)
        self.assertEquals(self.topic.member_count, 0)

        # Add first post by self.user (count += 1)
        user_post_1 = self.post
        self.assertEquals(self.parent_forum.member_count, 1)
        self.assertEquals(self.forum.member_count, 1)
        self.assertEquals(self.topic.member_count, 1)

        # Add first post by self.staff (count += 1)
        staff_post_1 = Post(topic=self.topic, user=self.staff, body='my new post')
        staff_post_1.save()
        self.assertEquals(self.parent_forum.member_count, 2)
        self.assertEquals(self.forum.member_count, 2)
        self.assertEquals(self.topic.member_count, 2)

        # Add second post by self.user (count += 0)
        user_post_2 = Post(topic=self.topic, user=self.user, body='my new post')
        user_post_2.save()
        self.assertEquals(self.parent_forum.member_count, 2)
        self.assertEquals(self.forum.member_count, 2)
        self.assertEquals(self.topic.member_count, 2)

        # Delete staff_post_1 (count -= 1)
        staff_post_1.mark_as_deleted(commit=True)
        self.assertEquals(self.parent_forum.member_count, 1)
        self.assertEquals(self.forum.member_count, 1)
        self.assertEquals(self.topic.member_count, 1)

        # Restore staff_post_1 (count += 1)
        staff_post_1.mark_as_undeleted(commit=True)
        self.assertEquals(self.parent_forum.member_count, 2)
        self.assertEquals(self.forum.member_count, 2)
        self.assertEquals(self.topic.member_count, 2)

        # Delete user_post_2 (count -= 0)
        user_post_2.mark_as_deleted(commit=True)
        self.assertEquals(self.parent_forum.member_count, 2)
        self.assertEquals(self.forum.member_count, 2)
        self.assertEquals(self.topic.member_count, 2)

        # Add third post by self.user in parent_forum (count += 0)
        new_topic = Topic(name='foo2', forum=self.parent_forum, user=self.user)
        new_topic.save()
        user_post_3 = Post(topic=new_topic, user=self.user, body='my new post')
        user_post_3.save()
        self.assertEquals(self.parent_forum.member_count, 2)
        self.assertEquals(new_topic.member_count, 1)
        self.assertEquals(self.forum.member_count, 2)
        self.assertEquals(self.topic.member_count, 2)
开发者ID:thoas,项目名称:pybbm,代码行数:53,代码来源:test_models.py


示例8: test_topic_deletion

 def test_topic_deletion(self):
     topic = Topic(name='xtopic', forum=self.forum, user=self.user)
     topic.save()
     post = Post(topic=topic, user=self.user, body='one')
     post.save()
     post = Post(topic=topic, user=self.user, body='two')
     post.save()
     post.delete()
     Topic.objects.get(id=topic.id)
     Forum.objects.get(id=self.forum.id)
     topic.delete()
     Forum.objects.get(id=self.forum.id)
开发者ID:thoas,项目名称:pybbm,代码行数:12,代码来源:test_features.py


示例9: test_topic_redirect_one_page

    def test_topic_redirect_one_page(self):
        topic = Topic(name='to-etopic', forum=self.forum, user=self.user)
        topic.save()

        response = self.client.get(reverse('pybb:topic_detail', kwargs={
            'forum_slug': self.forum.slug,
            'pk': topic.pk,
            'slug': topic.slug,
            'page': 1
        }))

        self.assertRedirects(response,
                             topic.get_absolute_url(),
                             301)
开发者ID:thoas,项目名称:pybbm,代码行数:14,代码来源:test_features.py


示例10: test_topic_updated

 def test_topic_updated(self):
     topic = Topic(name='etopic', forum=self.forum, user=self.user)
     topic.save()
     time.sleep(1)
     post = Post(topic=topic, user=self.user, body='bbcode [b]test[b]')
     post.save()
     client = Client()
     response = client.get(self.forum.get_absolute_url())
     self.assertEqual(response.context['topic_list'][0], topic)
     time.sleep(1)
     post = Post(topic=self.topic, user=self.user, body='bbcode [b]test[b]')
     post.save()
     client = Client()
     response = client.get(self.forum.get_absolute_url())
     self.assertEqual(response.context['topic_list'][0], self.topic)
开发者ID:thoas,项目名称:pybbm,代码行数:15,代码来源:test_features.py


示例11: test_topic_merge_view

    def test_topic_merge_view(self):
        topic = Topic(name='xtopic', forum=self.forum, user=self.user)
        topic.save()
        post = Post(topic=topic, user=self.user, body='one')
        post.save()

        topic_merge_url = reverse('pybb:topic_merge')

        self.login_as(self.staff)

        response = self.client.post(topic_merge_url, data={
            'topic_ids': [topic.pk]
        })

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['form'].forms), 1)
        self.assertTemplateUsed(response, 'pybb/topic/merge.html')
开发者ID:thoas,项目名称:pybbm,代码行数:17,代码来源:test_features.py


示例12: test_topic_merge_complete

    def test_topic_merge_complete(self):
        topic = Topic(name='xtopic', forum=self.forum, user=self.user)
        topic.save()
        post = Post(topic=topic, user=self.user, body='one')
        post.save()

        topic_merge_url = reverse('pybb:topic_merge')

        self.login_as(self.staff)

        response = self.client.post(topic_merge_url, data={
            'topic_ids': [topic.pk],
            'form-TOTAL_FORMS': 1,
            'form-INITIAL_FORMS': 0,
            'form-0-topic': self.topic.pk,
            'submit': 1
        })

        self.assertRedirects(response, reverse('pybb:index'))
开发者ID:thoas,项目名称:pybbm,代码行数:19,代码来源:test_features.py


示例13: test_compute

    def test_compute(self):
        # initials
        self.assertEqual(self.forum.forum_count, 0)
        self.assertEqual(self.parent_forum.forum_count, 1)

        self.topic
        self.post

        parent_forum = Forum.objects.get(pk=self.parent_forum.pk)

        self.assertEqual(parent_forum.topic_count, 1)
        self.assertEqual(parent_forum.post_count, 1)
        self.assertEqual(self.forum.topic_count, 1)
        self.assertEqual(self.forum.post_count, 1)

        forum = Forum.objects.create(name='bar', description='bar', forum=self.forum)

        topic = Topic(name='bar', forum=forum, user=self.user)
        topic.save()

        post = Post(topic=topic, user=self.user, body='my new post')
        post.save()

        self.assertEqual(topic.post_count, 1)
        self.assertEqual(forum.topic_count, 1)

        self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 2)
        self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 2)

        new_topic = Topic(name='foo', forum=self.forum, user=self.user)
        new_topic.save()

        new_post = Post(topic=topic, user=self.user, body='my new post')
        new_post.save()

        self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 3)
        self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 3)

        post.mark_as_deleted(commit=True)

        self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 2)
        self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 2)

        self.assertTrue(Topic.objects.get(pk=topic.pk).deleted)

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

        new_topic.mark_as_deleted()

        self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 1)
        self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 1)
开发者ID:magatz,项目名称:pybbm-1,代码行数:52,代码来源:tests.py


示例14: save

    def save(self, commit=True):
        if self.instance.pk:
            post = super(PostForm, self).save(commit=False)
            if self.user:
                post.user = self.user
            if post.topic.head == post:
                post.topic.name = self.cleaned_data['name']
                if self.may_create_poll:
                    post.topic.poll_type = self.cleaned_data['poll_type']
                    post.topic.poll_question = self.cleaned_data['poll_question']
                post.topic.updated = tznow()
                if commit:
                    post.topic.save()
            post.updated = tznow()
            if commit:
                post.save()
            return post, post.topic

        allow_post = True
        if defaults.PYBB_PREMODERATION:
            allow_post = defaults.PYBB_PREMODERATION(self.user, self.cleaned_data['body'])
        if self.forum:
            topic = Topic(
                forum=self.forum,
                user=self.user,
                name=self.cleaned_data['name'],
                poll_type=self.cleaned_data.get('poll_type', Topic.POLL_TYPE_NONE),
                poll_question=self.cleaned_data.get('poll_question', None),
                slug=self.cleaned_data.get('slug', None),
            )
            if not allow_post:
                topic.on_moderation = True
        else:
            topic = self.topic
        post = Post(user=self.user, user_ip=self.ip, body=self.cleaned_data['body'])
        if not allow_post:
            post.on_moderation = True
        if commit:
            topic.save()
            post.topic = topic
            post.save()
        return post, topic
开发者ID:DylannCordel,项目名称:pybbm,代码行数:42,代码来源:forms.py


示例15: save

    def save(self):

        if self.forum:
            topic = Topic(forum=self.forum, user=self.user, name=self.cleaned_data["name"])
            topic.save()
        else:
            topic = self.topic

        post = Post(
            topic=topic,
            user=self.user,
            user_ip=self.ip,
            markup=self.user.pybb_profile.markup,
            body=self.cleaned_data["body"],
        )
        post.save()

        if settings.PYBB_ATTACHMENT_ENABLE:
            for f in self.files:
                self.save_attachment(post, self.files[f])

        return post
开发者ID:xq2537,项目名称:pybb,代码行数:22,代码来源:forms.py


示例16: test_topic_redirect

    def test_topic_redirect(self):
        response = self.client.get(self.topic.get_absolute_url())
        self.assertEqual(response.status_code, 200)

        topic = Topic(name='to-etopic', forum=self.forum, user=self.user)
        topic.save()

        self.topic.redirect = True
        self.topic.save()

        redirection = TopicRedirection.objects.create(from_topic=self.topic, to_topic=topic)

        response = self.client.get(self.topic.get_absolute_url())

        self.assertRedirects(response, topic.get_absolute_url(), status_code=301)

        redirection.type = TopicRedirection.TYPE_NO_REDIRECT
        redirection.save()

        response = self.client.get(self.topic.get_absolute_url())

        self.assertEqual(response.status_code, 404)

        redirection.type = TopicRedirection.TYPE_EXPIRING_REDIRECT
        redirection.expired = date.today() + timedelta(days=1)
        redirection.save()

        response = self.client.get(self.topic.get_absolute_url())

        self.assertRedirects(response, topic.get_absolute_url())

        redirection.expired = date.today() - timedelta(days=1)
        redirection.save()

        response = self.client.get(self.topic.get_absolute_url())

        self.assertEqual(response.status_code, 404)
开发者ID:thoas,项目名称:pybbm,代码行数:37,代码来源:test_features.py


示例17: get_new_topic

    def get_new_topic(self):
        if hasattr(self, '_new_topic'):
            return self._new_topic
        if self.post.is_topic_head:
            topic = self.topic
        else:
            topic = Topic(user=self.post.user)

        if topic.name != self.cleaned_data['name']:
            topic.name = self.cleaned_data['name']
            # force slug auto-rebuild if slug is not speficied and topic is renamed
            topic.slug = self.cleaned_data.get('slug', None)
        elif self.cleaned_data.get('slug', None):
            topic.slug = self.cleaned_data['slug']

        topic.forum = Forum.objects.get(pk=self.cleaned_data['move_to'])
        topic.slug = create_or_check_slug(topic, Topic, forum=topic.forum)
        topic.save()
        return topic
开发者ID:chrisv2,项目名称:pybbm,代码行数:19,代码来源:forms.py


示例18: test_read_tracking_multi_user

    def test_read_tracking_multi_user(self):
        self.post

        topic_1 = self.topic
        topic_2 = Topic(name='topic_2', forum=self.forum, user=self.user)
        topic_2.save()

        Post(topic=topic_2, user=self.user, body='one').save()

        user_ann = get_user_model().objects.create_user('ann', '[email protected]', 'ann')
        client_ann = Client()
        client_ann.login(username='ann', password='ann')

        user_bob = get_user_model().objects.create_user('bob', '[email protected]', 'bob')
        client_bob = Client()
        client_bob.login(username='bob', password='bob')

        #  Two topics, each with one post. everything is unread, so the db should reflect that:
        self.assertEqual(TopicReadTracker.objects.all().count(), 0)
        self.assertEqual(ForumReadTracker.objects.all().count(), 0)

        #  user_ann reads topic_1, she should get one topic read tracker, there should be no forum read trackers
        client_ann.get(topic_1.get_absolute_url())
        self.assertEqual(TopicReadTracker.objects.all().count(), 1)
        self.assertEqual(TopicReadTracker.objects.filter(user=user_ann).count(), 1)
        self.assertEqual(TopicReadTracker.objects.filter(user=user_ann, topic=topic_1).count(), 1)
        self.assertEqual(ForumReadTracker.objects.all().count(), 0)

        #  user_bob reads topic_1, he should get one topic read tracker, there should be no forum read trackers
        client_bob.get(topic_1.get_absolute_url())
        self.assertEqual(TopicReadTracker.objects.all().count(), 2)
        self.assertEqual(TopicReadTracker.objects.filter(user=user_bob).count(), 1)
        self.assertEqual(TopicReadTracker.objects.filter(user=user_bob, topic=topic_1).count(), 1)
        self.assertEqual(ForumReadTracker.objects.all().count(), 0)

        #  user_bob reads topic_2, he should get a forum read tracker,
        #  there should be no topic read trackers for user_bob
        client_bob.get(topic_2.get_absolute_url())
        self.assertEqual(TopicReadTracker.objects.all().count(), 1)
        self.assertEqual(ForumReadTracker.objects.all().count(), 1)
        self.assertEqual(ForumReadTracker.objects.filter(user=user_bob).count(), 1)
        self.assertEqual(ForumReadTracker.objects.filter(user=user_bob, forum=self.forum).count(), 1)

        #  user_ann creates topic_3, there should be a new topic read tracker in the db
        topic_create_url = reverse('pybb:topic_create', kwargs={'forum_id': self.forum.id})
        response = client_ann.get(topic_create_url)
        values = self.get_form_values(response)
        values['body'] = 'topic_3'
        values['name'] = 'topic_3'
        values['poll_type'] = 0
        response = client_ann.post(topic_create_url, data=values, follow=True)

        self.assertEqual(TopicReadTracker.objects.all().count(), 2)
        self.assertEqual(TopicReadTracker.objects.filter(user=user_ann).count(), 2)
        self.assertEqual(ForumReadTracker.objects.all().count(), 1)

        topic_3 = Topic.objects.order_by('-updated')[0]
        self.assertEqual(topic_3.name, 'topic_3')

        #  user_ann posts to topic_1, a topic they've already read, no new trackers should be created (existing one is updated)
        post_create_url = reverse('pybb:post_create', kwargs={'topic_id': topic_1.id})
        response = client_ann.get(post_create_url)
        values = self.get_form_values(response)
        values['body'] = 'test tracking'
        response = client_ann.post(post_create_url, values, follow=True)
        self.assertEqual(TopicReadTracker.objects.all().count(), 2)
        self.assertEqual(TopicReadTracker.objects.filter(user=user_ann).count(), 2)
        self.assertEqual(ForumReadTracker.objects.all().count(), 1)

        self.assertEqual(ForumReadTracker.objects.all().count(), 1)
        previous_time = ForumReadTracker.objects.all()[0].time_stamp

        # user bob reads topic 1 which he already read, topic tracker recreated, forum tracker untouched (topic 3 still unread)
        client_bob.get(topic_1.get_absolute_url())
        self.assertEqual(ForumReadTracker.objects.all().count(), 1)
        self.assertEqual(ForumReadTracker.objects.all()[0].time_stamp, previous_time)
        self.assertEqual(TopicReadTracker.objects.all().count(), 3)
        self.assertEqual(TopicReadTracker.objects.filter(user=user_bob).count(), 1)

        self.assertEqual(ForumReadTracker.objects.all().count(), 1)
        previous_time = ForumReadTracker.objects.all()[0].time_stamp

        # user bob reads topic 3, topic tracker purged, forum tracker updated
        client_bob.get(topic_3.get_absolute_url())
        self.assertEqual(ForumReadTracker.objects.all().count(), 1)
        self.assertGreater(ForumReadTracker.objects.all()[0].time_stamp, previous_time)
        self.assertEqual(TopicReadTracker.objects.all().count(), 2)
        self.assertEqual(TopicReadTracker.objects.filter(user=user_bob).count(), 0)
开发者ID:thoas,项目名称:pybbm,代码行数:88,代码来源:test_trackers.py


示例19: test_staff

    def test_staff(self):
        client = Client()
        parent = Forum(name='hcat', staff=True)
        parent.save()

        forum_in_staff = Forum(name='in_staff', forum=parent)
        forum_in_staff.save()

        topic_in_staff = Topic(forum=forum_in_staff, name='in_staff', user=self.user)
        topic_in_staff.save()

        forum_staff = Forum(name='staff', forum=self.parent_forum, staff=True)
        forum_staff.save()

        topic_staff = Topic(forum=forum_staff, name='staff', user=self.user)
        topic_staff.save()

        post_staff = Post(topic=topic_staff, user=self.user, body='staff')
        post_staff.save()

        post_in_staff = Post(topic=topic_in_staff, user=self.user, body='staff')
        post_in_staff.save()

        self.assertFalse(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])
        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(forum_in_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(topic_in_staff.get_absolute_url()).status_code, 404)

        self.assertEqual(client.get(forum_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(topic_staff.get_absolute_url()).status_code, 404)

        client.login(username='zeus', password='zeus')

        self.assertFalse(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])

        self.assertNotContains(client.get(reverse('pybb:index')), forum_staff.get_absolute_url())

        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(forum_in_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(topic_in_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(forum_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(topic_staff.get_absolute_url()).status_code, 404)

        self.user.is_staff = True
        self.user.save()

        self.assertTrue(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])

        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_in_staff.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_in_staff.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_staff.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_staff.get_absolute_url()).status_code, 200)
开发者ID:thoas,项目名称:pybbm,代码行数:53,代码来源:test_features.py


示例20: test_hidden

    def test_hidden(self):
        client = Client()
        parent = Forum(name='hcat', hidden=True)
        parent.save()

        forum_in_hidden = Forum(name='in_hidden', forum=parent)
        forum_in_hidden.save()

        topic_in_hidden = Topic(forum=forum_in_hidden, name='in_hidden', user=self.user)
        topic_in_hidden.save()

        forum_hidden = Forum(name='hidden', forum=self.parent_forum, hidden=True)
        forum_hidden.save()

        topic_hidden = Topic(forum=forum_hidden, name='hidden', user=self.user)
        topic_hidden.save()

        post_hidden = Post(topic=topic_hidden, user=self.user, body='hidden')
        post_hidden.save()

        post_in_hidden = Post(topic=topic_in_hidden, user=self.user, body='hidden')
        post_in_hidden.save()

        self.assertFalse(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])
        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 302)
        self.assertEqual(client.get(forum_in_hidden.get_absolute_url()).status_code, 302)
        self.assertEqual(client.get(topic_in_hidden.get_absolute_url()).status_code, 302)

        self.assertNotContains(client.get(reverse('pybb:index')), forum_hidden.get_absolute_url())
        self.assertNotContains(client.get(reverse('pybb:feed_topics')), topic_hidden.get_absolute_url())
        self.assertNotContains(client.get(reverse('pybb:feed_topics')), topic_in_hidden.get_absolute_url())

        self.assertNotContains(client.get(reverse('pybb:feed_posts')), post_hidden.get_absolute_url())
        self.assertNotContains(client.get(reverse('pybb:feed_posts')), post_in_hidden.get_absolute_url())
        self.assertEqual(client.get(forum_hidden.get_absolute_url()).status_code, 302)
        self.assertEqual(client.get(topic_hidden.get_absolute_url()).status_code, 302)

        client.login(username='zeus', password='zeus')

        self.assertTrue(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])

        self.assertContains(client.get(reverse('pybb:index')), forum_hidden.get_absolute_url())

        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_hidden.get_absolute_url()).status_code, 200)
        self.user.is_staff = True
        self.user.save()
        self.assertTrue(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])
        self.assertContains(client.get(reverse('pybb:index')), forum_hidden.get_absolute_url())

        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_hidden.get_absolute_url()).status_code, 200)
开发者ID:thoas,项目名称:pybbm,代码行数:58,代码来源:test_features.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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