示例#1
0
    def test_render_poll_form_user(self):
        """
        should load initial or not
        """
        poll_choice = TopicPollChoice.objects.create(poll=self.poll, description="op2")
        TopicPollVote.objects.create(user=self.user, choice=poll_choice)

        self.user.is_authenticated = lambda: True
        context = render_poll_form(self.topic, self.user)
        self.assertDictEqual(context["form"].initial, {"choices": poll_choice})

        self.user.is_authenticated = lambda: False
        context = render_poll_form(self.topic, self.user)
        self.assertDictEqual(context["form"].initial, {})
示例#2
0
    def test_render_poll_form_user(self):
        """
        should load initial or not
        """
        poll_choice = TopicPollChoice.objects.create(poll=self.poll, description="op2")
        poll_vote = TopicPollVote.objects.create(user=self.user, choice=poll_choice)

        self.user.is_authenticated = lambda: True
        context = render_poll_form(self.topic, self.user)
        self.assertDictEqual(context['form'].initial, {'choices': poll_choice})

        self.user.is_authenticated = lambda: False
        context = render_poll_form(self.topic, self.user)
        self.assertDictEqual(context['form'].initial, {})
示例#3
0
    def test_render_poll_form(self):
        """
        should display poll vote form
        """
        out = Template("{% load spirit_tags %}" "{% render_poll_form topic=topic user=user %}").render(
            Context({"topic": self.topic, "user": self.user})
        )
        self.assertNotEqual(out.strip(), "")

        context = render_poll_form(self.topic, self.user)
        self.assertEqual(context["next"], None)
        self.assertIsInstance(context["form"], TopicPollVoteManyForm)
        self.assertEqual(context["poll"], self.poll)
示例#4
0
    def test_render_poll_form(self):
        """
        should display poll vote form
        """
        out = Template(
            "{% load spirit_tags %}"
            "{% render_poll_form topic=topic user=user %}"
        ).render(Context({'topic': self.topic, 'user': self.user}))
        self.assertNotEqual(out.strip(), "")

        context = render_poll_form(self.topic, self.user)
        self.assertEqual(context['next'], None)
        self.assertIsInstance(context['form'], TopicPollVoteManyForm)
        self.assertEqual(context['poll'], self.poll)