示例#1
0
 def test_base(self):
     poll = PollFactory.create()
     range_poll = RangePollFactory.create(poll=poll)
     RangePollChoiceFactory.create(range_poll=range_poll)
     data = {'range_poll__{0}'.format(range_poll.choices.all()[0].id): u'1'}
     vote_form = forms.RangePollChoiceVoteForm(data=data,
                                               choices=range_poll.choices.all())
     ok_(vote_form.is_valid())
示例#2
0
 def test_base(self):
     poll = PollFactory.create()
     range_poll = RangePollFactory.create(poll=poll)
     RangePollChoiceFactory.create(range_poll=range_poll)
     data = {'range_poll__{0}'.format(range_poll.choices.all()[0].id): u'1'}
     vote_form = forms.RangePollChoiceVoteForm(
         data=data, choices=range_poll.choices.all())
     ok_(vote_form.is_valid())
示例#3
0
 def test_invalid(self):
     poll = PollFactory.create()
     range_poll = RangePollFactory.create(poll=poll)
     RangePollChoiceFactory.create(range_poll=range_poll)
     field_name = 'range_poll__{0}'.format(range_poll.choices.all()[0].id)
     data = {field_name: u'0'}
     vote_form = forms.RangePollChoiceVoteForm(data=data,
                                               choices=range_poll.choices.all())
     ok_(not vote_form.is_valid())
     ok_(field_name in vote_form.errors)
     ok_(vote_form[field_name], 'You must vote at least one nominee')
示例#4
0
 def test_invalid(self):
     poll = PollFactory.create()
     range_poll = RangePollFactory.create(poll=poll)
     RangePollChoiceFactory.create(range_poll=range_poll)
     field_name = 'range_poll__{0}'.format(range_poll.choices.all()[0].id)
     data = {field_name: u'0'}
     vote_form = forms.RangePollChoiceVoteForm(
         data=data, choices=range_poll.choices.all())
     ok_(not vote_form.is_valid())
     ok_(field_name in vote_form.errors)
     ok_(vote_form[field_name], 'You must vote at least one nominee')
示例#5
0
    def setUp(self):
        """Initial data for the tests."""
        self.nominee1, self.nominee2, self.nominee3 = UserFactory.create_batch(3, groups=['Rep'])
        self.rep = UserFactory.create(groups=['Rep'])
        self.admin = UserFactory.create(groups=['Admin', 'Rep'])
        self.mozillian = UserFactory.create(groups=['Mozillians'])
        poll_start = now() + timedelta(days=5)
        self.admin_group = Group.objects.get(name='Admin')
        self.rep_group = Group.objects.get(name='Rep')
        self.poll = PollFactory.create(valid_groups=self.admin_group,
                                       start=poll_start,
                                       end=poll_start + timedelta(days=10),
                                       comments_allowed=False)
        self.range_poll = RangePollFactory(poll=self.poll)
        self.range_poll_choice1 = RangePollChoiceFactory(range_poll=self.range_poll,
                                                         nominee=self.nominee1)
        self.range_poll_choice2 = RangePollChoiceFactory(range_poll=self.range_poll,
                                                         nominee=self.nominee2)
        self.radio_poll = RadioPollFactory(poll=self.poll)
        self.radio_poll_choice1, self.radio_poll_choice2 = RadioPollChoiceFactory.create_batch(
            2, radio_poll=self.radio_poll)

        self.post_data = {'range_poll__1': 1,
                          'range_poll__2': 2,
                          'radio_poll__1': 2}

        self.edit_future_data = {
            'name': u'Test edit voting',
            'description': u'This is a description.',
            'created_by': self.poll.created_by.id,
            'valid_groups': self.admin_group.id,
            'start_form_0_year': now().year + 1,
            'start_form_0_month': 10,
            'start_form_0_day': 1,
            'start_form_1_hour': 7,
            'start_form_1_minute': 00,
            'end_form_0_year': now().year + 1,
            'end_form_0_month': 10,
            'end_form_0_day': 4,
            'end_form_1_hour': 7,
            'end_form_1_minute': 00,
            'range_polls-TOTAL_FORMS': u'1',
            'range_polls-INITIAL_FORMS': u'1',
            'range_polls-MAX_NUM_FORMS': u'1000',
            'range_polls-0-id': self.range_poll.id,
            'range_polls-0-name': u'Current Range Poll 1',
            '{0}_range_choices-0-id'.format(self.range_poll.id): self.range_poll_choice1.id,
            '{0}_range_choices-0-nominee'.format(self.range_poll.id): self.nominee1.id,
            '{0}_range_choices-0-DELETE'.format(self.range_poll.id): False,
            '{0}_range_choices-1-id'.format(self.range_poll.id): self.range_poll_choice2.id,
            '{0}_range_choices-1-nominee'.format(self.range_poll.id): self.nominee2.id,
            '{0}_range_choices-1-DELETE'.format(self.range_poll.id): False,
            '{0}_range_choices-2-id'.format(self.range_poll.id): u'',
            '{0}_range_choices-2-nominee'.format(self.range_poll.id): self.nominee3.id,
            '{0}_range_choices-2-DELETE'.format(self.range_poll.id): False,
            '{0}_range_choices-TOTAL_FORMS'.format(self.range_poll.id): u'3',
            '{0}_range_choices-INITIAL_FORMS'.format(self.range_poll.id): u'2',
            '{0}_range_choices-TOTAL_FORMS'.format(self.range_poll.id): u'1000',
            'radio_polls-0-id': self.radio_poll.id,
            'radio_polls-0-question': u'Radio Poll - Question 1',
            'radio_polls-TOTAL_FORMS': u'1',
            'radio_polls-INITIAL_FORMS': u'1',
            'radio_polls-MAX_NUM_FORMS': u'1000',
            '{0}_radio_choices-TOTAL_FORMS'.format(self.radio_poll.id): u'2',
            '{0}_radio_choices-INITIAL_FORMS'.format(self.radio_poll.id): u'2',
            '{0}_radio_choices-MAX_NUM_FORMS'.format(self.radio_poll.id): u'1000',
            '{0}_radio_choices-0-id'.format(self.radio_poll.id): self.radio_poll_choice1.id,
            '{0}_radio_choices-0-answer'.format(self.radio_poll.id): u'Radio Poll - Answer 1',
            '{0}_radio_choices-0-DELETE'.format(self.radio_poll.id): False,
            '{0}_radio_choices-1-id'.format(self.radio_poll.id): self.radio_poll_choice2.id,
            '{0}_radio_choices-1-answer'.format(self.radio_poll.id): u'Radio Poll - Answer 2',
            '{0}_radio_choices-1-DELETE'.format(self.radio_poll.id): False}

        self.edit_current_data = {
            'name': u'Test edit voting',
            'description': u'This is a description.',
            'created_by': self.nominee1.id,
            'valid_groups': self.admin_group.id,
            'start_form_0_year': 2011,
            'end_form_0_year': now().year,
            'end_form_0_month': 10,
            'end_form_0_day': 4,
            'end_form_1_hour': 7,
            'end_form_1_minute': 00}

        # Give permissions to admin group
        group = Group.objects.get(name='Admin')
        permissions = Permission.objects.filter(name__icontains='poll')
        for perm in permissions:
            group.permissions.add(perm)
示例#6
0
    def setUp(self):
        """Initial setup for the tests."""
        self.poll = PollFactory.create()
        self.radio_poll = RadioPollFactory.create(poll=self.poll)
        self.radio_poll_choice = (
            RadioPollChoiceFactory.create(radio_poll=self.radio_poll))
        self.range_poll = RangePollFactory.create(poll=self.poll)
        self.range_poll_choice = (
            RangePollChoiceFactory.create(range_poll=self.range_poll))
        UserFactory.create_batch(20, groups=['Rep'])
        self.user_list = (
            User.objects.filter(groups__name='Rep',
                                userprofile__registration_complete=True))
        self.user = self.user_list[0]

        self.form_data = {
            'description': u'This is a description.',
            'end_form_0_day': u'10',
            'end_form_0_month': u'2',
            'end_form_0_year': u'{0}'.format(now().year + 2),
            'end_form_1_hour': u'12',
            'end_form_1_minute': u'00',
            'name': u'Form data.',
            'start_form_0_day': u'10',
            'start_form_0_month': u'2',
            'start_form_0_year': u'{0}'.format(now().year + 1),
            'start_form_1_hour': u'12',
            'start_form_1_minute': u'00',
            'valid_groups': u'1'}

        self.radio_formset_data = {
            'radio_polls-0-id': u'%d' % self.radio_poll.id,
            'radio_polls-0-question': u'Radio Poll Example 2 - Question 1',
            'radio_polls-TOTAL_FORMS': u'1',
            'radio_polls-INITIAL_FORMS': u'1',
            'radio_polls-MAX_NUM_FORMS': u'1000',
            '%d_radio_choices-TOTAL_FORMS' % self.radio_poll.id: u'1',
            '%d_radio_choices-INITIAL_FORMS' % self.radio_poll.id: u'1',
            '%d_radio_choices-MAX_NUM_FORMS' % self.radio_poll.id: u'1000',
            '%d_radio_choices-0-id' % self.radio_poll.id: (
                u'%d' % self.radio_poll_choice.id),
            '%d_radio_choices-0-answer' % self.radio_poll.id: u'Answer 1',
            '%d_radio_choices-0-DELETE' % self.radio_poll.id: False}

        self.range_formset_data = {
            'range_polls-TOTAL_FORMS': u'1',
            'range_polls-INITIAL_FORMS': u'1',
            'range_polls-MAX_NUM_FORMS': u'1000',
            'range_polls-0-id': u'%d' % self.range_poll.id,
            'range_polls-0-name': u'Current Range Poll 1',
            '%d_range_choices-0-id' % self.range_poll.id: (
                u'%d' % self.range_poll.id),
            '%d_range_choices-0-nominee' % self.range_poll.id: (
                u'%d' % self.user.id),
            '%d_range_choices-0-DELETE' % self.range_poll.id: False,
            '%d_range_choices-TOTAL_FORMS' % self.range_poll.id: u'1',
            '%d_range_choices-INITIAL_FORMS' % self.range_poll.id: u'1',
            '%d_range_choices-MAX_NUM_FORMS' % self.range_poll.id: u'1000'}

        self.empty_radio_formset = {
            'radio_polls-TOTAL_FORMS': u'0',
            'radio_polls-INITIAL_FORMS': u'0',
            'radio_polls-MAX_NUM_FORMS': u'1000'}

        self.empty_range_formset = {
            'range_polls-TOTAL_FORMS': u'0',
            'range_polls-INITIAL_FORMS': u'0',
            'range_polls-MAX_NUM_FORMS': u'1000'}

        RangePollFormset = inlineformset_factory(Poll,
                                                 RangePoll,
                                                 formset=forms.BaseRangePollInlineFormSet,
                                                 extra=1,
                                                 exclude=('votes',),
                                                 can_delete=True)
        RadioPollFormset = inlineformset_factory(Poll,
                                                 RadioPoll,
                                                 formset=forms.BaseRadioPollInlineFormSet,
                                                 extra=1,
                                                 can_delete=True,
                                                 exclude=('votes',))

        self.range_poll_formset = RangePollFormset(self.range_formset_data,
                                                   instance=self.poll,
                                                   user_list=self.user_list)
        self.radio_poll_formset = RadioPollFormset(self.radio_formset_data, instance=self.poll)
        self.radio_poll_formset_empty = RadioPollFormset(self.empty_radio_formset,
                                                         instance=self.poll)
        self.range_poll_formset_empty = RangePollFormset(self.empty_range_formset,
                                                         instance=self.poll,
                                                         user_list=self.user_list)
示例#7
0
    def setUp(self):
        """Initial setup for the tests."""
        self.poll = PollFactory.create()
        self.radio_poll = RadioPollFactory.create(poll=self.poll)
        self.radio_poll_choice = (RadioPollChoiceFactory
                                  .create(radio_poll=self.radio_poll))
        self.range_poll = RangePollFactory.create(poll=self.poll)
        self.range_poll_choice = (RangePollChoiceFactory
                                  .create(range_poll=self.range_poll))

        self.form_data = {
            'description': u'This is a description.',
            'end_form_0_day': u'1',
            'end_form_0_month': u'1',
            'end_form_0_year': u'2019',
            'end_form_1_hour': u'12',
            'end_form_1_minute': u'00',
            'name': u'Form data.',
            'start_form_0_day': u'1',
            'start_form_0_month': u'1',
            'start_form_0_year': u'2018',
            'start_form_1_hour': u'12',
            'start_form_1_minute': u'00',
            'valid_groups': u'1'}

        self.radio_formset_data = {
            'radio_polls-0-id': u'%s' % str(self.radio_poll.id),
            'radio_polls-0-question': u'Radio Poll Example 2 - Question 1',
            'radio_polls-TOTAL_FORMS': u'1',
            'radio_polls-INITIAL_FORMS': u'1',
            'radio_polls-MAX_NUM_FORMS': u'1000',
            '%s_radio_choices-TOTAL_FORMS' % str(self.radio_poll.id): u'1',
            '%s_radio_choices-INITIAL_FORMS' % str(self.radio_poll.id): u'1',
            '%s_radio_choices-MAX_NUM_FORMS' % (
                str(self.radio_poll.id)): u'1000',
            '%s_radio_choices-0-id' % str(self.radio_poll.id): u'1',
            '%s_radio_choices-0-answer' % str(self.radio_poll.id): u'Answer 1',
            '%s_radio_choices-0-DELETE' % str(self.radio_poll.id): False}

        self.range_formset_data = {
            'range_polls-TOTAL_FORMS': u'1',
            'range_polls-INITIAL_FORMS': u'1',
            'range_polls-MAX_NUM_FORMS': u'1000',
            'range_polls-0-id': u'%s' % str(self.range_poll.id),
            'range_polls-0-name': u'Current Range Poll 1',
            '%s_range_choices-0-id' % str(self.range_poll.id): u'1',
            '%s_range_choices-0-nominee' % self.range_poll.id: u'4',
            '%s_range_choices-0-DELETE' % str(self.range_poll.id): False,
            '%s_range_choices-TOTAL_FORMS' % str(self.range_poll.id): u'1',
            '%s_range_choices-INITIAL_FORMS' % str(self.range_poll.id): u'1',
            '%s_range_choices-MAX_NUM_FORMS' % (
                str(self.range_poll.id)): u'1000'}

        self.radio_formset_invalid_data = {
            'radio_polls-TOTAL_FORMS': u'0',
            'radio_polls-INITIAL_FORMS': u'0',
            'radio_polls-MAX_NUM_FORMS': u'1000',
            '%s_radio_choices-TOTAL_FORMS' % str(self.radio_poll.id): u'0',
            '%s_radio_choices-INITIAL_FORMS' % str(self.radio_poll.id): u'0',
            '%s_radio_choices-MAX_NUM_FORMS' % (
                str(self.radio_poll.id)): u'1000'}

        self.range_formset_invalid_data = {
            'range_polls-TOTAL_FORMS': u'0',
            'range_polls-INITIAL_FORMS': u'0',
            'range_polls-MAX_NUM_FORMS': u'1000',
            '%s_range_choices-TOTAL_FORMS' % str(self.range_poll.id): u'0',
            '%s_range_choices-INITIAL_FORMS' % str(self.range_poll.id): u'0',
            '%s_range_choices-TOTAL_FORMS' % (
                str(self.range_poll.id)): u'1000'}

        RangePollFormset = (inlineformset_factory(Poll, RangePoll,
                            formset=forms.BaseRangePollInlineFormSet,
                            extra=1, can_delete=True))
        RadioPollFormset = (inlineformset_factory(Poll, RadioPoll,
                            formset=forms.BaseRadioPollInlineFormSet,
                            extra=1, can_delete=True))
        self.range_poll_formset = RangePollFormset(self.range_formset_data,
                                                   instance=self.poll)
        self.radio_poll_formset = RadioPollFormset(self.radio_formset_data,
                                                   instance=self.poll)
        self.radio_poll_formset_invalid = RadioPollFormset(
            self.radio_formset_invalid_data, instance=self.poll)
        self.range_poll_formset_invalid = RangePollFormset(
            self.range_formset_invalid_data, instance=self.poll)
示例#8
0
    def setUp(self):
        """Initial setup for the tests."""
        self.poll = PollFactory.create()
        self.radio_poll = RadioPollFactory.create(poll=self.poll)
        self.radio_poll_choice = (RadioPollChoiceFactory.create(
            radio_poll=self.radio_poll))
        self.range_poll = RangePollFactory.create(poll=self.poll)
        self.range_poll_choice = (RangePollChoiceFactory.create(
            range_poll=self.range_poll))
        UserFactory.create_batch(20, groups=['Rep'])
        self.user_list = (User.objects.filter(
            groups__name='Rep', userprofile__registration_complete=True))
        self.user = self.user_list[0]

        self.form_data = {
            'description': u'This is a description.',
            'end_form_0_day': u'1',
            'end_form_0_month': u'1',
            'end_form_0_year': u'2019',
            'end_form_1_hour': u'12',
            'end_form_1_minute': u'00',
            'name': u'Form data.',
            'start_form_0_day': u'1',
            'start_form_0_month': u'1',
            'start_form_0_year': u'2018',
            'start_form_1_hour': u'12',
            'start_form_1_minute': u'00',
            'valid_groups': u'1'
        }

        self.radio_formset_data = {
            'radio_polls-0-id':
            u'%d' % self.radio_poll.id,
            'radio_polls-0-question':
            u'Radio Poll Example 2 - Question 1',
            'radio_polls-TOTAL_FORMS':
            u'1',
            'radio_polls-INITIAL_FORMS':
            u'1',
            'radio_polls-MAX_NUM_FORMS':
            u'1000',
            '%d_radio_choices-TOTAL_FORMS' % self.radio_poll.id:
            u'1',
            '%d_radio_choices-INITIAL_FORMS' % self.radio_poll.id:
            u'1',
            '%d_radio_choices-MAX_NUM_FORMS' % self.radio_poll.id:
            u'1000',
            '%d_radio_choices-0-id' % self.radio_poll.id:
            (u'%d' % self.radio_poll_choice.id),
            '%d_radio_choices-0-answer' % self.radio_poll.id:
            u'Answer 1',
            '%d_radio_choices-0-DELETE' % self.radio_poll.id:
            False
        }

        self.range_formset_data = {
            'range_polls-TOTAL_FORMS':
            u'1',
            'range_polls-INITIAL_FORMS':
            u'1',
            'range_polls-MAX_NUM_FORMS':
            u'1000',
            'range_polls-0-id':
            u'%d' % self.range_poll.id,
            'range_polls-0-name':
            u'Current Range Poll 1',
            '%d_range_choices-0-id' % self.range_poll.id:
            (u'%d' % self.range_poll.id),
            '%d_range_choices-0-nominee' % self.range_poll.id:
            (u'%d' % self.user.id),
            '%d_range_choices-0-DELETE' % self.range_poll.id:
            False,
            '%d_range_choices-TOTAL_FORMS' % self.range_poll.id:
            u'1',
            '%d_range_choices-INITIAL_FORMS' % self.range_poll.id:
            u'1',
            '%d_range_choices-MAX_NUM_FORMS' % self.range_poll.id:
            u'1000'
        }

        self.empty_radio_formset = {
            'radio_polls-TOTAL_FORMS': u'0',
            'radio_polls-INITIAL_FORMS': u'0',
            'radio_polls-MAX_NUM_FORMS': u'1000'
        }

        self.empty_range_formset = {
            'range_polls-TOTAL_FORMS': u'0',
            'range_polls-INITIAL_FORMS': u'0',
            'range_polls-MAX_NUM_FORMS': u'1000'
        }

        RangePollFormset = inlineformset_factory(
            Poll,
            RangePoll,
            formset=forms.BaseRangePollInlineFormSet,
            extra=1,
            can_delete=True)
        RadioPollFormset = inlineformset_factory(
            Poll,
            RadioPoll,
            formset=forms.BaseRadioPollInlineFormSet,
            extra=1,
            can_delete=True)

        self.range_poll_formset = (RangePollFormset(self.range_formset_data,
                                                    instance=self.poll,
                                                    user_list=self.user_list))
        self.radio_poll_formset = (RadioPollFormset(self.radio_formset_data,
                                                    instance=self.poll))
        self.radio_poll_formset_empty = (RadioPollFormset(
            self.empty_radio_formset, instance=self.poll))
        self.range_poll_formset_empty = (RangePollFormset(
            self.empty_range_formset,
            instance=self.poll,
            user_list=self.user_list))