示例#1
0
    def test_stats_per_classification(self):
        PopularProposal.objects.create(proposer=self.fiera,
                                       area=self.arica,
                                       data=self.data,
                                       title=u'This is a title',
                                       clasification=TOPIC_CHOICES[1][0])
        PopularProposal.objects.create(proposer=self.fiera,
                                       area=self.arica,
                                       data=self.data,
                                       title=u'This is a title',
                                       clasification=TOPIC_CHOICES[2][0])
        PopularProposal.objects.create(proposer=self.fiera,
                                       area=self.arica,
                                       data=self.data,
                                       title=u'This is a title',
                                       clasification=TOPIC_CHOICES[3][0])
        PopularProposal.objects.create(proposer=self.fiera,
                                       area=self.arica,
                                       data=self.data,
                                       title=u'This is a title',
                                       clasification=TOPIC_CHOICES[3][0])

        stats = Stats()
        count = stats.per_classification_proposals_count
        self.assertEquals(count[TOPIC_CHOICES[1][0]], 1)
        self.assertEquals(count[TOPIC_CHOICES[2][0]], 1)
        self.assertEquals(count[TOPIC_CHOICES[3][0]], 2)
示例#2
0
 def tests_get_local_meetings(self):
     stats = Stats()
     PopularProposal.objects.create(proposer=self.fiera,
                                    area=self.arica,
                                    data=self.data,
                                    title=u'This is a title',
                                    clasification=u'education')
     PopularProposal.objects.create(proposer=self.fiera,
                                    area=self.arica,
                                    data=self.data,
                                    is_local_meeting=True,
                                    title=u'This is a title',
                                    clasification=u'education')
     PopularProposal.objects.create(proposer=self.fiera,
                                    area=self.arica,
                                    data=self.data,
                                    title=u'This is a title',
                                    is_local_meeting=True,
                                    clasification=u'education')
     self.assertEquals(stats.local_gatherings(), 2)
 def tests_get_local_meetings(self):
     stats = Stats()
     PopularProposal.objects.create(proposer=self.fiera,
                                    area=self.arica,
                                    data=self.data,
                                    title=u'This is a title',
                                    clasification=u'education'
                                    )
     PopularProposal.objects.create(proposer=self.fiera,
                                    area=self.arica,
                                    data=self.data,
                                    is_local_meeting=True,
                                    title=u'This is a title',
                                    clasification=u'education'
                                    )
     PopularProposal.objects.create(proposer=self.fiera,
                                    area=self.arica,
                                    data=self.data,
                                    title=u'This is a title',
                                    is_local_meeting=True,
                                    clasification=u'education'
                                    )
     self.assertEquals(stats.local_gatherings(), 2)
示例#4
0
    def test_stats_v2_organizations_supporting(self):
        User.objects.all().delete()
        stats = Stats()
        org = User.objects.create_user(username='******',
                                       password='******')
        org.profile.is_organization = True
        org.profile.save()
        org2 = User.objects.create_user(username='******',
                                        password='******')
        org2.profile.is_organization = True
        org2.profile.save()
        normal_user = User.objects.create_user(username='******')

        popular_proposal = PopularProposal.objects.create(
            proposer=normal_user,
            area=self.arica,
            data=self.data,
            title=u'This is a title',
            clasification=u'education')
        ProposalLike.objects.create(user=org, proposal=popular_proposal)
        another_user = User.objects.create_user(username='******')
        ProposalLike.objects.create(user=another_user,
                                    proposal=popular_proposal)
        self.assertEquals(stats.likes_by_organizations, 1)
        self.assertEquals(stats.organizations_online.count(), 2)

        PopularProposal.objects.create(proposer=org2,
                                       area=self.arica,
                                       data=self.data,
                                       title=u'This is a title',
                                       clasification=u'education')
        PopularProposal.objects.create(proposer=org,
                                       area=self.arica,
                                       data=self.data,
                                       title=u'This is a title',
                                       clasification=u'education')
        PopularProposal.objects.create(proposer=org,
                                       area=self.arica,
                                       data=self.data,
                                       title=u'This is a title',
                                       clasification=u'education')
        self.assertEquals(stats.proposals_made_by_organizations.count(), 3)
        self.assertIn(org, stats.organizations.all())
        self.assertIn(org2, stats.organizations.all())
        self.assertNotIn(normal_user, stats.organizations.all())
        self.assertEquals(stats.likes, ProposalLike.objects.count())
        self.assertEquals(stats.likers,
                          User.objects.filter(likes__isnull=False).count())
示例#5
0
    def test_stats_mixin(self):
        User.objects.all().delete()
        stats = Stats()
        self.assertTrue(Candidate.objects.count())
        self.assertEquals(stats.total_candidates(), Candidate.objects.count())
        self.assertEquals(
            stats.total_candidates_alcalde(),
            Election.objects.get(position='alcalde').candidates.count())
        self.assertEquals(
            stats.total_candidates_concejal(),
            Election.objects.get(position='concejal').candidates.count())

        candidates_in_alcaldes_ids = []
        for c in Election.objects.get(position='alcalde').candidates.all():
            candidates_in_alcaldes_ids.append(c.id)

        for c in Election.objects.get(position='concejal').candidates.all():
            self.assertNotIn(c.id, candidates_in_alcaldes_ids)

        # Candidate one has connected
        user1 = User.objects.create_user(username='******', password='******')
        self.client.login(username=user1.username, password='******')

        candidacy1 = Candidacy.objects.create(user=user1,
                                              candidate=self.candidate1)
        CandidacyContact.objects.create(candidate=self.candidate1,
                                        used_by_candidate=True,
                                        candidacy=candidacy1)

        # Candidate 2 got an email but hasn't read it
        user2 = User.objects.create_user(username='******', password='******')

        candidacy2 = Candidacy.objects.create(user=user2,
                                              candidate=self.candidate2)
        CandidacyContact.objects.create(candidate=self.candidate2,
                                        used_by_candidate=False,
                                        candidacy=candidacy2)
        # Candidate 3 we have no contact with her
        user3 = User.objects.create_user(username='******')

        Candidacy.objects.create(user=user3, candidate=self.candidate3)

        # Candidate four has connected
        user4 = User.objects.create_user(username='******', password='******')
        self.client.login(username=user4.username, password='******')

        candidacy4 = Candidacy.objects.create(user=user4,
                                              candidate=self.candidate4)
        CandidacyContact.objects.create(candidate=self.candidate4,
                                        used_by_candidate=True,
                                        candidacy=candidacy4)

        # Candidate 5 got an email but hasn't read it
        user5 = User.objects.create_user(username='******')

        candidacy5 = Candidacy.objects.create(user=user5,
                                              candidate=self.candidate5)
        CandidacyContact.objects.create(candidate=self.candidate5,
                                        used_by_candidate=False,
                                        candidacy=candidacy5)
        # Candidate 6 we have no contact with her
        user6 = User.objects.create_user(username='******')

        Candidacy.objects.create(user=user6, candidate=self.candidate6)

        self.assertEquals(stats.participation().with_us, 2)
        self.assertEquals(stats.participation().got_email, 2)
        self.assertGreater(stats.participation().no_contact, 2)

        self.assertEquals(stats.participation_alcalde().with_us, 1)
        self.assertEquals(stats.participation_alcalde().got_email, 1)
        self.assertEquals(stats.participation_alcalde().no_contact, 1)

        self.assertEquals(stats.participation_concejal().with_us, 1)
        self.assertEquals(stats.participation_concejal().got_email, 1)
        self.assertEquals(stats.participation_concejal().no_contact, 1)

        popular_proposal = PopularProposal.objects.create(
            proposer=self.fiera,
            area=self.arica,
            data=self.data,
            title=u'This is a title',
            clasification=u'education')
        popular_proposal2 = PopularProposal.objects.create(
            proposer=self.fiera,
            area=self.arica,
            data=self.data,
            title=u'This is a title',
            clasification=u'education')
        PopularProposal.objects.create(proposer=self.fiera,
                                       area=self.arica,
                                       data=self.data,
                                       title=u'This is a title',
                                       clasification=u'education',
                                       for_all_areas=True)
        Commitment.objects.create(candidate=self.candidate1,
                                  proposal=popular_proposal,
                                  detail=u'Yo me comprometo',
                                  commited=True)
        Commitment.objects.create(candidate=self.candidate1,
                                  proposal=popular_proposal2,
                                  detail=u'Yo me comprometo',
                                  commited=True)
        self.assertEquals(stats.proposals(), 2)
        self.assertEquals(stats.commitments(), 2)
        self.assertEquals(stats.candidates_that_have_commited(), 1)
        Commitment.objects.create(candidate=self.candidate6,
                                  proposal=popular_proposal2,
                                  detail=u'Yo me comprometo',
                                  commited=True)

        self.assertEquals(stats.candidates_that_have_commited(), 2)
        self.assertEquals(stats.candidates_that_have_commited_alcalde(), 1)
        self.assertEquals(stats.candidates_that_have_commited_concejal(), 1)
        self.assertIn(popular_proposal,
                      stats.proposals_with_commitments().all())
        self.assertIn(popular_proposal2,
                      stats.proposals_with_commitments().all())

        self.candidate6.taken_positions.all().delete()
        self.assertIn(self.candidate1,
                      stats.candidates_that_have_12_naranja().all())
        self.assertIn(self.candidate2,
                      stats.candidates_that_have_12_naranja().all())
        self.assertIn(self.candidate3,
                      stats.candidates_that_have_12_naranja().all())
        self.assertIn(self.candidate4,
                      stats.candidates_that_have_12_naranja().all())
        self.assertIn(self.candidate5,
                      stats.candidates_that_have_12_naranja().all())
        self.assertNotIn(self.candidate6,
                         stats.candidates_that_have_12_naranja().all())

        self.assertEquals(stats.candidates_that_have_12_naranja().count(), 5)
        election = self.candidate1.election
        election.position = 'alcalde'
        election.save()
        self.assertIn(self.candidate1,
                      stats.candidates_that_have_12_naranja__alcalde().all())
        self.assertIn(self.candidate2,
                      stats.candidates_that_have_12_naranja__alcalde().all())
        self.assertIn(self.candidate3,
                      stats.candidates_that_have_12_naranja__alcalde().all())

        self.assertIn(self.candidate4,
                      stats.candidates_that_have_12_naranja__alcalde().all())
        self.assertIn(self.candidate5,
                      stats.candidates_that_have_12_naranja__alcalde().all())
    def test_stats_mixin(self):
        stats = Stats()
        self.assertTrue(Candidate.objects.count())
        self.assertEquals(stats.total_candidates(), Candidate.objects.count())
        self.assertEquals(stats.total_candidates_alcalde(),
                          Election.objects.get(position='alcalde').candidates.count())
        self.assertEquals(stats.total_candidates_concejal(),
                          Election.objects.get(position='concejal').candidates.count())

        candidates_in_alcaldes_ids = []
        for c in Election.objects.get(position='alcalde').candidates.all():
            candidates_in_alcaldes_ids.append(c.id)

        for c in Election.objects.get(position='concejal').candidates.all():
            self.assertNotIn(c.id, candidates_in_alcaldes_ids)

        # Candidate one has connected
        user1 = User.objects.create_user(username='******', password='******')
        self.client.login(username=user1.username, password='******')

        candidacy1 = Candidacy.objects.create(user=user1, candidate=self.candidate1)
        CandidacyContact.objects.create(candidate=self.candidate1,
                                        used_by_candidate=True,
                                        candidacy=candidacy1)

        # Candidate 2 got an email but hasn't read it
        user2 = User.objects.create_user(username='******', password='******')

        candidacy2 = Candidacy.objects.create(user=user2, candidate=self.candidate2)
        CandidacyContact.objects.create(candidate=self.candidate2,
                                        used_by_candidate=False,
                                        candidacy=candidacy2
                                        )
        # Candidate 3 we have no contact with her
        user3 = User.objects.create_user(username='******')

        Candidacy.objects.create(user=user3, candidate=self.candidate3)

        # Candidate four has connected
        user4 = User.objects.create_user(username='******', password='******')
        self.client.login(username=user4.username, password='******')

        candidacy4 = Candidacy.objects.create(user=user4, candidate=self.candidate4)
        CandidacyContact.objects.create(candidate=self.candidate4,
                                        used_by_candidate=True,
                                        candidacy=candidacy4)

        # Candidate 5 got an email but hasn't read it
        user5 = User.objects.create_user(username='******')

        candidacy5 = Candidacy.objects.create(user=user5, candidate=self.candidate5)
        CandidacyContact.objects.create(candidate=self.candidate5,
                                        used_by_candidate=False,
                                        candidacy=candidacy5
                                        )
        # Candidate 6 we have no contact with her
        user6 = User.objects.create_user(username='******')

        Candidacy.objects.create(user=user6, candidate=self.candidate6)

        self.assertEquals(stats.participation().with_us, 2)
        self.assertEquals(stats.participation().got_email, 2)
        self.assertGreater(stats.participation().no_contact, 1)

        self.assertEquals(stats.participation_alcalde().with_us, 1)
        self.assertEquals(stats.participation_alcalde().got_email, 1)
        self.assertEquals(stats.participation_alcalde().no_contact, 1)

        self.assertEquals(stats.participation_concejal().with_us, 1)
        self.assertEquals(stats.participation_concejal().got_email, 1)
        self.assertEquals(stats.participation_concejal().no_contact, 1)

        popular_proposal = PopularProposal.objects.create(proposer=self.fiera,
                                                          area=self.arica,
                                                          data=self.data,
                                                          title=u'This is a title',
                                                          clasification=u'education'
                                                          )
        popular_proposal2 = PopularProposal.objects.create(proposer=self.fiera,
                                                           area=self.arica,
                                                           data=self.data,
                                                           title=u'This is a title',
                                                           clasification=u'education'
                                                           )
        PopularProposal.objects.create(proposer=self.fiera,
                                       area=self.arica,
                                       data=self.data,
                                       title=u'This is a title',
                                       clasification=u'education',
                                       for_all_areas=True
                                       )
        Commitment.objects.create(candidate=self.candidate1,
                                  proposal=popular_proposal,
                                  detail=u'Yo me comprometo',
                                  commited=True)
        Commitment.objects.create(candidate=self.candidate1,
                                  proposal=popular_proposal2,
                                  detail=u'Yo me comprometo',
                                  commited=True)
        self.assertEquals(stats.proposals(), 2)
        self.assertEquals(stats.commitments(), 2)
        self.assertEquals(stats.candidates_that_have_commited(), 1)
        Commitment.objects.create(candidate=self.candidate6,
                                  proposal=popular_proposal2,
                                  detail=u'Yo me comprometo',
                                  commited=True)

        self.assertEquals(stats.candidates_that_have_commited(), 2)
        self.assertEquals(stats.candidates_that_have_commited_alcalde(), 1)
        self.assertEquals(stats.candidates_that_have_commited_concejal(), 1)
        self.assertIn(popular_proposal, stats.proposals_with_commitments().all())
        self.assertIn(popular_proposal2, stats.proposals_with_commitments().all())

        self.candidate6.taken_positions.all().delete()
        self.assertIn(self.candidate1, stats.candidates_that_have_12_naranja().all())
        self.assertIn(self.candidate2, stats.candidates_that_have_12_naranja().all())
        self.assertIn(self.candidate3, stats.candidates_that_have_12_naranja().all())
        self.assertIn(self.candidate4, stats.candidates_that_have_12_naranja().all())
        self.assertIn(self.candidate5, stats.candidates_that_have_12_naranja().all())
        self.assertNotIn(self.candidate6, stats.candidates_that_have_12_naranja().all())

        self.assertEquals(stats.candidates_that_have_12_naranja().count(), 5)
        election = self.candidate1.election
        election.position = 'alcalde'
        election.save()
        self.assertIn(self.candidate1, stats.candidates_that_have_12_naranja__alcalde().all())
        self.assertIn(self.candidate2, stats.candidates_that_have_12_naranja__alcalde().all())
        self.assertIn(self.candidate3, stats.candidates_that_have_12_naranja__alcalde().all())

        self.assertIn(self.candidate4, stats.candidates_that_have_12_naranja__alcalde().all())
        self.assertIn(self.candidate5, stats.candidates_that_have_12_naranja__alcalde().all())