当前位置: 首页>>代码示例>>Python>>正文


Python TopicPollFactory.create方法代码示例

本文整理汇总了Python中machina.test.factories.TopicPollFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python TopicPollFactory.create方法的具体用法?Python TopicPollFactory.create怎么用?Python TopicPollFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在machina.test.factories.TopicPollFactory的用法示例。


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

示例1: test_can_tell_if_a_user_can_vote_in_a_poll

# 需要导入模块: from machina.test.factories import TopicPollFactory [as 别名]
# 或者: from machina.test.factories.TopicPollFactory import create [as 别名]
    def test_can_tell_if_a_user_can_vote_in_a_poll(self):
        # Setup
        def get_rendered(poll, user):
            request = self.request_factory.get('/')
            request.user = user
            ForumPermissionHandlerMiddleware().process_request(request)
            t = Template(
                self.loadstatement + '{% get_permission \'can_vote_in_poll\' poll request.user as user_can_vote_in_poll %}'
                '{% if user_can_vote_in_poll %}CAN_VOTE{% else %}CANNOT_VOTE{% endif %}')
            c = Context({'poll': poll, 'request': request})
            rendered = t.render(c)

            return rendered

        self.poll_1 = TopicPollFactory.create(topic=self.forum_1_topic)
        self.poll_2 = TopicPollFactory.create(topic=self.forum_2_topic)

        assign_perm('can_see_forum', self.g1, self.forum_1)
        assign_perm('can_read_forum', self.g1, self.forum_1)
        assign_perm('can_edit_own_posts', self.g1, self.forum_1)
        assign_perm('can_delete_own_posts', self.g1, self.forum_1)
        assign_perm('can_reply_to_topics', self.g1, self.forum_1)
        assign_perm('can_see_forum', self.moderators, self.forum_1)
        assign_perm('can_read_forum', self.moderators, self.forum_1)
        assign_perm('can_edit_own_posts', self.moderators, self.forum_1)
        assign_perm('can_delete_own_posts', self.moderators, self.forum_1)
        assign_perm('can_edit_posts', self.moderators, self.forum_1)
        assign_perm('can_delete_posts', self.moderators, self.forum_1)
        assign_perm('can_vote_in_polls', self.g1, self.forum_1)

        # Run & check
        assert get_rendered(self.poll_1, self.u1) == 'CAN_VOTE'
        assert get_rendered(self.poll_2, self.u1) == 'CANNOT_VOTE'
        assert get_rendered(self.poll_1, self.superuser) == 'CAN_VOTE'
        assert get_rendered(self.poll_2, self.superuser) == 'CAN_VOTE'
开发者ID:harish211,项目名称:django-machina,代码行数:37,代码来源:test_permission_tags.py

示例2: test_knows_if_a_user_can_vote_in_polls

# 需要导入模块: from machina.test.factories import TopicPollFactory [as 别名]
# 或者: from machina.test.factories.TopicPollFactory import create [as 别名]
 def test_knows_if_a_user_can_vote_in_polls(self):
     # Setup
     poll_1 = TopicPollFactory.create(topic=self.forum_1_topic)
     poll_2 = TopicPollFactory.create(topic=self.forum_3_topic)
     poll_3 = TopicPollFactory.create(topic=self.forum_3_topic_2)
     assign_perm('can_vote_in_polls', self.u1, self.forum_1)
     # Run & check
     assert self.perm_handler.can_vote_in_poll(poll_1, self.u1)
     assert not self.perm_handler.can_vote_in_poll(poll_2, self.u1)
     assert not self.perm_handler.can_vote_in_poll(poll_3, self.u1)
开发者ID:swcheon,项目名称:django-machina,代码行数:12,代码来源:test_handler.py

示例3: test_knows_that_an_anonymous_user_without_forum_key_cannot_vote_in_polls

# 需要导入模块: from machina.test.factories import TopicPollFactory [as 别名]
# 或者: from machina.test.factories.TopicPollFactory import create [as 别名]
 def test_knows_that_an_anonymous_user_without_forum_key_cannot_vote_in_polls(self):
     # Setup
     u3 = AnonymousUser()
     poll_1 = TopicPollFactory.create(topic=self.forum_1_topic)
     poll_2 = TopicPollFactory.create(topic=self.forum_3_topic)
     poll_3 = TopicPollFactory.create(topic=self.forum_3_topic_2)
     assign_perm('can_vote_in_polls', u3, self.forum_1)
     # Run & check
     assert not self.perm_handler.can_vote_in_poll(poll_1, u3)
     assert not self.perm_handler.can_vote_in_poll(poll_2, u3)
     assert not self.perm_handler.can_vote_in_poll(poll_3, u3)
开发者ID:swcheon,项目名称:django-machina,代码行数:13,代码来源:test_handler.py

示例4: test_can_initialize_poll_fields_from_topic_related_poll_object

# 需要导入模块: from machina.test.factories import TopicPollFactory [as 别名]
# 或者: from machina.test.factories.TopicPollFactory import create [as 别名]
 def test_can_initialize_poll_fields_from_topic_related_poll_object(self):
     # Setup
     form_data = {
         'subject': 'Re: {}'.format(faker.text(max_nb_chars=200)),
         'content': '[b]{}[/b]'.format(faker.text()),
         'topic_type': Topic.TYPE_CHOICES.topic_sticky,
     }
     assign_perm('can_create_polls', self.user, self.top_level_forum)
     poll = TopicPollFactory.create(topic=self.post.topic)
     # Run
     form = TopicForm(
         data=form_data,
         user=self.user,
         user_ip=faker.ipv4(),
         forum=self.top_level_forum,
         topic=self.topic,
         instance=self.post)
     # Check
     assert 'poll_question' in form.fields
     assert 'poll_max_options' in form.fields
     assert 'poll_duration' in form.fields
     assert 'poll_user_changes' in form.fields
     assert form.fields['poll_question'].initial == poll.question
     assert form.fields['poll_max_options'].initial == poll.max_options
     assert form.fields['poll_duration'].initial == poll.duration
     assert form.fields['poll_user_changes'].initial == poll.user_changes
开发者ID:nephila,项目名称:django-machina,代码行数:28,代码来源:test_forms.py

示例5: test_append_empty_forms_only_when_no_initial_data_is_provided

# 需要导入模块: from machina.test.factories import TopicPollFactory [as 别名]
# 或者: from machina.test.factories.TopicPollFactory import create [as 别名]
 def test_append_empty_forms_only_when_no_initial_data_is_provided(self):
     # Setup
     poll = TopicPollFactory.create(topic=self.topic)
     option_1 = TopicPollOptionFactory.create(poll=poll)
     option_2 = TopicPollOptionFactory.create(poll=poll)
     form_data_1 = {
         'form-0-id': option_1.pk,
         'form-0-text': faker.text(max_nb_chars=100),
         'form-1-id': option_2.pk,
         'form-1-text': option_2.text,
         'form-INITIAL_FORMS': 2,
         'form-TOTAL_FORMS': 2,
         'form-MAX_NUM_FORMS': 1000,
     }
     self.topic.refresh_from_db()
     # Run
     form_1 = TopicPollOptionFormset(
         data=form_data_1,
         topic=self.topic)
     form_2 = TopicPollOptionFormset(topic=self.topic)  # poll already created
     form_3 = TopicPollOptionFormset(topic=self.alt_topic)  # no poll
     # Check
     assert form_1.total_form_count() == 2
     assert form_2.total_form_count() == 2
     assert form_3.total_form_count() == 2
开发者ID:ellmetha,项目名称:django-machina,代码行数:27,代码来源:test_forms.py

示例6: test_can_update_options_associated_with_an_existing_poll

# 需要导入模块: from machina.test.factories import TopicPollFactory [as 别名]
# 或者: from machina.test.factories.TopicPollFactory import create [as 别名]
 def test_can_update_options_associated_with_an_existing_poll(self):
     # Setup
     poll = TopicPollFactory.create(topic=self.topic)
     option_1 = TopicPollOptionFactory.create(poll=poll)
     option_2 = TopicPollOptionFactory.create(poll=poll)
     form_data = {
         'form-0-id': option_1.pk,
         'form-0-text': faker.text(max_nb_chars=100),
         'form-1-id': option_2.pk,
         'form-1-text': option_2.text,
         'form-INITIAL_FORMS': 2,
         'form-TOTAL_FORMS': 2,
         'form-MAX_NUM_FORMS': 1000,
     }
     self.topic.refresh_from_db()
     # Run
     form = TopicPollOptionFormset(
         data=form_data,
         topic=self.topic)
     valid = form.is_valid()
     # Check
     assert valid
     form.save()
     option_1.refresh_from_db()
     assert option_1.text == form_data['form-0-text']
开发者ID:ellmetha,项目名称:django-machina,代码行数:27,代码来源:test_forms.py

示例7: setup

# 需要导入模块: from machina.test.factories import TopicPollFactory [as 别名]
# 或者: from machina.test.factories.TopicPollFactory import create [as 别名]
    def setup(self):
        self.loadstatement = '{% load forum_polls_tags %}'
        self.request_factory = RequestFactory()

        self.g1 = GroupFactory.create()
        self.u1 = UserFactory.create()
        self.u2 = UserFactory.create()
        self.u1.groups.add(self.g1)
        self.u2.groups.add(self.g1)
        self.moderators = GroupFactory.create()
        self.moderator = UserFactory.create()
        self.moderator.groups.add(self.moderators)
        self.superuser = UserFactory.create(is_superuser=True)

        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level category
        self.top_level_cat = create_category_forum()

        # Set up some forums
        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)

        # Set up some topics and posts
        self.forum_1_topic = create_topic(forum=self.forum_1, poster=self.u1)
        self.forum_2_topic = create_topic(forum=self.forum_2, poster=self.u2)
        self.post_1 = PostFactory.create(topic=self.forum_1_topic, poster=self.u1)
        self.post_2 = PostFactory.create(topic=self.forum_2_topic, poster=self.u2)
        self.poll_1 = TopicPollFactory.create(topic=self.forum_1_topic)
        self.poll_2 = TopicPollFactory.create(topic=self.forum_2_topic)

        # Assign some permissions
        assign_perm('can_see_forum', self.g1, self.forum_1)
        assign_perm('can_read_forum', self.g1, self.forum_1)
        assign_perm('can_edit_own_posts', self.g1, self.forum_1)
        assign_perm('can_delete_own_posts', self.g1, self.forum_1)
        assign_perm('can_reply_to_topics', self.g1, self.forum_1)
        assign_perm('can_see_forum', self.moderators, self.forum_1)
        assign_perm('can_read_forum', self.moderators, self.forum_1)
        assign_perm('can_edit_own_posts', self.moderators, self.forum_1)
        assign_perm('can_delete_own_posts', self.moderators, self.forum_1)
        assign_perm('can_edit_posts', self.moderators, self.forum_1)
        assign_perm('can_delete_posts', self.moderators, self.forum_1)
        assign_perm('can_vote_in_polls', self.g1, self.forum_1)
开发者ID:ellmetha,项目名称:django-machina,代码行数:47,代码来源:test_polls_tags.py

示例8: test_knows_if_a_user_can_vote_again_in_a_poll

# 需要导入模块: from machina.test.factories import TopicPollFactory [as 别名]
# 或者: from machina.test.factories.TopicPollFactory import create [as 别名]
    def test_knows_if_a_user_can_vote_again_in_a_poll(self):
        # Setup
        poll_1 = TopicPollFactory.create(topic=self.forum_1_topic, user_changes=True)
        poll_option_1 = TopicPollOptionFactory.create(poll=poll_1)
        TopicPollOptionFactory.create(poll=poll_1)

        poll_2 = TopicPollFactory.create(topic=self.forum_3_topic)
        poll_option_2 = TopicPollOptionFactory.create(poll=poll_2)
        TopicPollOptionFactory.create(poll=poll_2)

        TopicPollVoteFactory.create(poll_option=poll_option_1, voter=self.u1)
        TopicPollVoteFactory.create(poll_option=poll_option_2, voter=self.u1)

        assign_perm('can_vote_in_polls', self.u1, self.forum_1)
        assign_perm('can_vote_in_polls', self.u1, self.forum_3)
        # Run & check
        assert self.perm_handler.can_vote_in_poll(poll_1, self.u1)
        assert not self.perm_handler.can_vote_in_poll(poll_2, self.u1)
开发者ID:swcheon,项目名称:django-machina,代码行数:20,代码来源:test_handler.py

示例9: test_knows_that_a_user_should_no_vote_in_a_completed_poll

# 需要导入模块: from machina.test.factories import TopicPollFactory [as 别名]
# 或者: from machina.test.factories.TopicPollFactory import create [as 别名]
 def test_knows_that_a_user_should_no_vote_in_a_completed_poll(self):
     # Setup
     poll = TopicPollFactory.create(topic=self.forum_1_topic, duration=2)
     poll._meta.get_field('updated').auto_now = False
     poll.created = dt.datetime(2000, 1, 12)
     poll.save()
     poll._meta.get_field('updated').auto_now = True
     assign_perm('can_vote_in_polls', self.u1, self.forum_1)
     # Run & check
     assert not self.perm_handler.can_vote_in_poll(poll, self.u1)
开发者ID:swcheon,项目名称:django-machina,代码行数:12,代码来源:test_handler.py

示例10: test_cannot_be_associated_with_a_user_and_a_session_key_at_the_same_time_to_be_created

# 需要导入模块: from machina.test.factories import TopicPollFactory [as 别名]
# 或者: from machina.test.factories.TopicPollFactory import create [as 别名]
    def test_cannot_be_associated_with_a_user_and_a_session_key_at_the_same_time_to_be_created(self):  # noqa
        # Setup
        poll = TopicPollFactory.create(topic=self.topic, max_options=2)
        option_1 = TopicPollOptionFactory.create(poll=poll)
        TopicPollOptionFactory.create(poll=poll)

        # Run & check
        with pytest.raises(ValidationError):
            vote = TopicPollVoteFactory.build(
                poll_option=option_1, voter=self.u1, anonymous_key='ertyue')
            vote.clean()
开发者ID:ellmetha,项目名称:django-machina,代码行数:13,代码来源:test_models.py

示例11: test_must_be_associated_with_a_user_or_a_session_key_to_be_created

# 需要导入模块: from machina.test.factories import TopicPollFactory [as 别名]
# 或者: from machina.test.factories.TopicPollFactory import create [as 别名]
    def test_must_be_associated_with_a_user_or_a_session_key_to_be_created(self):
        # Setup
        poll = TopicPollFactory.create(topic=self.topic, max_options=2)
        option_1 = TopicPollOptionFactory.create(poll=poll)
        TopicPollOptionFactory.create(poll=poll)

        # Run & check
        with pytest.raises(ValidationError):
            vote = TopicPollVoteFactory.build(
                poll_option=option_1, voter=None, anonymous_key=None)
            vote.clean()
开发者ID:ellmetha,项目名称:django-machina,代码行数:13,代码来源:test_models.py

示例12: test_knows_if_an_anonymous_user_can_vote_again_in_a_poll

# 需要导入模块: from machina.test.factories import TopicPollFactory [as 别名]
# 或者: from machina.test.factories.TopicPollFactory import create [as 别名]
    def test_knows_if_an_anonymous_user_can_vote_again_in_a_poll(self):
        # Setup
        u3 = AnonymousUser()
        u3.forum_key = 1
        poll_1 = TopicPollFactory.create(topic=self.forum_1_topic, user_changes=True)
        poll_option_1 = TopicPollOptionFactory.create(poll=poll_1)
        TopicPollOptionFactory.create(poll=poll_1)

        poll_2 = TopicPollFactory.create(topic=self.forum_3_topic)
        poll_option_2 = TopicPollOptionFactory.create(poll=poll_2)
        TopicPollOptionFactory.create(poll=poll_2)

        TopicPollVoteFactory.create(poll_option=poll_option_1, anonymous_key=1)
        TopicPollVoteFactory.create(poll_option=poll_option_2, anonymous_key=1)

        assign_perm('can_vote_in_polls', u3, self.forum_1)
        assign_perm('can_vote_in_polls', u3, self.forum_3)
        # Run & check
        assert self.perm_handler.can_vote_in_poll(poll_1, u3)
        assert not self.perm_handler.can_vote_in_poll(poll_2, u3)
开发者ID:swcheon,项目名称:django-machina,代码行数:22,代码来源:test_handler.py

示例13: test_can_return_a_list_of_all_related_votes

# 需要导入模块: from machina.test.factories import TopicPollFactory [as 别名]
# 或者: from machina.test.factories.TopicPollFactory import create [as 别名]
 def test_can_return_a_list_of_all_related_votes(self):
     # Setup
     u2 = UserFactory.create()
     poll = TopicPollFactory.create(topic=self.topic, max_options=2)
     option_1 = TopicPollOptionFactory.create(poll=poll)
     option_2 = TopicPollOptionFactory.create(poll=poll)
     # Run
     vote_1 = TopicPollVoteFactory.create(poll_option=option_1, voter=self.u1)
     vote_2 = TopicPollVoteFactory.create(poll_option=option_2, voter=self.u1)
     vote_3 = TopicPollVoteFactory.create(poll_option=option_2, voter=u2)
     # Check
     assert set(poll.votes) == set([vote_1, vote_2, vote_3])
开发者ID:harish211,项目名称:django-machina,代码行数:14,代码来源:test_models.py

示例14: test_knows_its_percentage

# 需要导入模块: from machina.test.factories import TopicPollFactory [as 别名]
# 或者: from machina.test.factories.TopicPollFactory import create [as 别名]
 def test_knows_its_percentage(self):
     # Setup
     u2 = UserFactory.create()
     poll = TopicPollFactory.create(topic=self.topic, max_options=2)
     option_1 = TopicPollOptionFactory.create(poll=poll)
     option_2 = TopicPollOptionFactory.create(poll=poll)
     TopicPollVoteFactory.create(poll_option=option_1, voter=self.u1)
     TopicPollVoteFactory.create(poll_option=option_2, voter=self.u1)
     TopicPollVoteFactory.create(poll_option=option_1, voter=u2)
     TopicPollVoteFactory.create(poll_option=option_2, voter=u2)
     # Run & check
     assert option_1.percentage == 50
     assert option_2.percentage == 50
开发者ID:harish211,项目名称:django-machina,代码行数:15,代码来源:test_models.py

示例15: test_inserts_the_topic_poll_in_the_context_if_applicable

# 需要导入模块: from machina.test.factories import TopicPollFactory [as 别名]
# 或者: from machina.test.factories.TopicPollFactory import create [as 别名]
 def test_inserts_the_topic_poll_in_the_context_if_applicable(self):
     # Setup
     poll = TopicPollFactory.create(topic=self.topic)
     option_1 = TopicPollOptionFactory.create(poll=poll)
     option_2 = TopicPollOptionFactory.create(poll=poll)
     correct_url = reverse(
         'forum_moderation:queued_post', kwargs={'pk': self.post.pk})
     # Run
     response = self.client.get(correct_url, follow=True)
     # Check
     assert response.status_code == 200
     assert response.context['poll'] == poll
     assert set(response.context['poll_options']) == set({option_1, option_2, })
开发者ID:ashwin31,项目名称:django-machina,代码行数:15,代码来源:test_views.py


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