Esempio n. 1
0
    def test_idea_no_support(self, render):
        """
        Check support = False if no votes.
        """
        user = random_user()
        state = models.State.objects.get(name='Active')
        idea = models.Idea(creator=user, title='title', text='text',
                state=state)
        idea.save()

        for _ in range(7):
            models.Vote(creator=random_user(), idea=idea).save()

        views.detail(mock_req(), str(idea.id))
        context = render.call_args[0][2]
        self.assertTrue('support' in context)
        self.assertFalse(context['support'])
Esempio n. 2
0
    def test_members_with_voters(self):
        user = random_user()
        idea = models.Idea(creator=user,
                           title='Transit subsidy to Mars',
                           text='Aliens need assistance.',
                           state=self.state)
        idea.save()

        voter = random_user()
        self.assertNotEqual(user, voter)
        vote = models.Vote()
        vote.idea = idea
        vote.creator = voter
        vote.save()

        self.assertEqual(len(idea.members), 1)
        self.assertNotIn(voter, idea.members)
        self.assertIn(user, idea.members)
Esempio n. 3
0
 def create_timestamp_event(idea, nonce):
     # add future timestamp for vote for items 0, 2, 4
     if nonce % 2 == 0:
         models.Vote(creator=idea.creator,
                     idea=idea,
                     time=datetime.datetime(
                         2050, 1, nonce,
                         tzinfo=get_default_timezone())).save()
     # add future timestamp for comment for items 1, 5
     elif nonce != 3:
         MPTTComment(content_type=idea_type,
                     site=site,
                     object_pk=idea.pk,
                     user=idea.creator,
                     comment='Blah',
                     submit_date=datetime.datetime(
                         2050, 1, nonce,
                         tzinfo=get_default_timezone())).save()
Esempio n. 4
0
    def test_idea_voters(self, render):
        """
        The idea passed to the ui should have the correct voters.
        """
        user = User.objects.create_user('example')
        state = models.State.objects.get(name='Active')
        idea = models.Idea(creator=user, title='title', text='text',
                state=state)
        idea.save()

        users = []
        for i in range(5):
            users.append(User.objects.create_user('example' + str(i)))
            models.Vote(creator=users[i], idea=idea).save()

        views.detail(mock_req(), str(idea.id))
        context = render.call_args[0][2]
        self.assertTrue('voters' in context)
        self.assertEqual(5, len(context['voters']))
        self.assertEqual(set([u.id for u in users]), 
                set([v.id for v in context['voters']]))
Esempio n. 5
0
 def create_votes(idea, nonce):
     for _ in range(nonce):
         models.Vote(creator=idea.creator, idea=idea).save()