Exemplo n.º 1
0
    def test_updates_answer(self):
        UpdatingDataCandidator.install_candidator_yaml()
        Election.fetch_all_from_api()

        UpdatingDataCandidator.install_candidator_yaml(yaml_file='candidator_example_data_with_answers2')
        Election.fetch_all_from_api()

        juanito = Candidate.objects.all()[0]


        paros = Question.objects.get(question='Esta de a cuerdo con los paros?')
        marchas = Question.objects.get(question='Le gusta ir a las marchas?')
        carretear = Question.objects.get(question='Quiere gastar su plata carreteando?')
        plata = Question.objects.get(question='Quiere robarse la plata del CEI?')
        # paros_asnwers = 
        answers_for_paros = paros.answer_set.all()
        number_of_answers_for_paros = 0
        for answer_for_paros in answers_for_paros:
            number_of_answers_for_paros += answer_for_paros.candidate_set.all().count()



        self.assertEquals(juanito.answers.get(question=paros).caption, u'Estoy de acuerdo con algunos paros')
        self.assertEquals(juanito.answers.get(question=marchas).caption, u'Siempre')
        self.assertEquals(juanito.answers.get(question=plata).caption, u'No')
        self.assertEquals(juanito.answers.get(question=carretear).caption, u'A veces')
        self.assertEquals(paros.number_of_answers,1)
        paros.answer_set.all().delete()
        self.assertEquals(paros.number_of_answers,0)
Exemplo n.º 2
0
    def test_associate_answers(self):
        # Candidate.objects.all().delete()
        Election.fetch_all_from_api()
        candidate1 = Candidate.objects.get(resource_uri="/api/v2/candidate/1/")
        answer8 = Answer.objects.get(resource_uri="/api/v2/answer/8/")

        self.assertIn(answer8, candidate1.answers.all())
Exemplo n.º 3
0
    def test_election_update_with_a_celery_task(self):

        Election.fetch_all_from_api()

        UpdatingDataCandidator.install_candidator_yaml(yaml_file='candidator_example_data_with_answers2')

        election = Election.objects.all()[0]

        result = election_updater.delay(election)

        self.assertTrue(result.successful())

        juanito = Candidate.objects.all()[0]
        self.assertEquals(juanito.answers.all().count(), 4)
        
        
        
        marchas = Question.objects.get(question='Le gusta ir a las marchas?')
        self.assertEquals(juanito.answers.get(question=marchas).caption, u'Siempre')
        
        carretear = Question.objects.get(question='Quiere gastar su plata carreteando?')
        self.assertEquals(juanito.answers.get(question=carretear).caption, u'A veces')
        
        plata = Question.objects.get(question='Quiere robarse la plata del CEI?')
        self.assertEquals(juanito.answers.get(question=plata).caption, u'No')

        paros = Question.objects.get(question='Esta de a cuerdo con los paros?')
        self.assertEquals(juanito.answers.get(question=paros).caption, u'Estoy de acuerdo con algunos paros')
Exemplo n.º 4
0
 def test_upgrade_data(self):
     Election.fetch_all_from_api()
     Election.fetch_all_from_api()
     self.assertEquals(Election.objects.count(), 1)
     self.assertEquals(Category.objects.count(), 2)
     self.assertEquals(Candidate.objects.count(), 3)
     self.assertEquals(BackgroundCategory.objects.count(),2)
     self.assertEquals(PersonalData.objects.count(),4)
     self.assertEquals(Background.objects.count(),4)
     self.assertEquals(BackgroundCategory.objects.count(),2)
Exemplo n.º 5
0
    def test_pull_from_api_and_relates(self):
        Election.fetch_all_from_api()

        candidate = Candidate.objects.get(resource_uri="/api/v2/candidate/1/")
        question = Question.objects.get(resource_uri="/api/v2/question/1/")

        information_source = InformationSource.objects.all()[0]
        self.assertEquals(information_source.candidate, candidate)
        self.assertEquals(information_source.question, question)
        self.assertEquals(information_source.content, u'Esta de a cuerdo con los paros?')
Exemplo n.º 6
0
    def test_fetch_all_personaldata_from_api(self):
        self.election.delete()
        Election.fetch_all_from_api()
        election = Election.objects.all()[0]

        self.assertEquals(PersonalData.objects.count(),4)

        personal_data = PersonalData.objects.all()[0]
        self.assertEquals(personal_data.label,'Nacimiento')
        self.assertEquals(personal_data.election, election)
Exemplo n.º 7
0
    def test_get_links_from_api(self):
        self.election.delete()
        Election.fetch_all_from_api()

        election = Election.objects.all()[0]
        candidate = Candidate.objects.all()[0]
        link = Link.objects.all()[0]
        
        self.assertEquals(Link.objects.count(),1)
        self.assertEquals(link.url, 'http://www.twitter.com')
Exemplo n.º 8
0
    def test_fetch_all_background_candidates_from_api(self):
        self.election.delete()
        Election.fetch_all_from_api()
        election = Election.objects.all()[0]

        self.assertEquals(BackgroundCategory.objects.count(),2)

        bg_categorie = BackgroundCategory.objects.all()[0]
        self.assertEquals(bg_categorie.remote_id,1)
        self.assertEquals(bg_categorie.name,'Tendencia Politica')
        self.assertEquals(bg_categorie.election,election)
Exemplo n.º 9
0
    def test_fetch_all_background_from_api(self):
        self.election.delete()
        Election.fetch_all_from_api()
        election = Election.objects.all()[0]
        background_category = BackgroundCategory.objects.get(remote_id=1)

        self.assertEquals(Background.objects.count(),4)
        background = Background.objects.get(remote_id=1)
        self.assertEquals(background.name,'Partido politico actual')
        self.assertEquals(background.resource_uri,'/api/v2/background/1/')
        self.assertEquals(background.background_category, background_category)
Exemplo n.º 10
0
    def test_get_all_question_from_api(self):
        self.election.delete()
        Election.fetch_all_from_api()
        election = Election.objects.all()[0]
        category = Category.objects.all()[0]

        self.assertEquals(Question.objects.count(),4)
        question = Question.objects.all()[0]
        self.assertEquals(question.question, 'Esta de a cuerdo con los paros?')
        self.assertEquals(question.category, category)
        self.assertEquals(question.resource_uri, '/api/v2/question/1/')
Exemplo n.º 11
0
    def test_call_command_update_single_person(self):
        UpdatingDataCandidator.install_candidator_yaml()
        Election.fetch_all_from_api()
        election = Election.objects.all()[0]
        candidate = election.candidate_set.get(name="Juanito Perez")

        UpdatingDataCandidator.install_candidator_yaml(yaml_file='candidator_example_data_with_answers2')

        personaldata = election.personaldata_set.get(label=u'Profesion')
        call_command('update_candidate_from_candidator', candidate.id)
        personal_data_candidate = personaldata.personaldatacandidate_set.get(candidate=candidate)
        self.assertEquals(personal_data_candidate.value, u"Grande")
Exemplo n.º 12
0
    def test_fetch_all_answers_from_api(self):
        self.election.delete()
        Election.fetch_all_from_api()
        election = Election.objects.all()[0]
        category = Category.objects.all()[0]
        question = Question.objects.all()[0]

        self.assertEquals(Answer.objects.count(),10)
        answer = Answer.objects.get(remote_id=9)
        self.assertEquals(answer.caption,'Puro perder clases')
        self.assertEquals(answer.resource_uri,'/api/v2/answer/9/')
        self.assertEquals(answer.question, question)
Exemplo n.º 13
0
    def test_get_all_personal_data_candidate_from_api(self):
        self.election.delete()
        Election.fetch_all_from_api()

        election = Election.objects.all()[0]
        candidate = Candidate.objects.all()[0]
        personal_data = PersonalData.objects.all()[0]

        self.assertEquals(PersonalDataCandidate.objects.count(),2)
        personal_data_candidate = PersonalDataCandidate.objects.all()[0]
        self.assertEquals(personal_data_candidate.value,'13/13/13')
        self.assertEquals(personal_data_candidate.candidate, candidate)
        self.assertEquals(personal_data_candidate.personaldata, personal_data)
Exemplo n.º 14
0
    def test_fetch_all_election(self):
        Election.fetch_all_from_api()
        self.assertEquals(Election.objects.count(), 1)

        election = Election.objects.all()[0]
        self.assertEquals(election.description, 'Elecciones CEI 2012')
        self.assertEquals(election.remote_id, 1)
        self.assertEquals(election.information_source, '')
        self.assertEquals(election.logo, '/media/photos/dummy.jpg')
        self.assertEquals(election.name, 'cei 2012')
        self.assertEquals(election.resource_uri, '/api/v2/election/1/')
        self.assertEquals(election.slug, 'cei-2012')
        self.assertTrue(election.use_default_media_naranja_option)
Exemplo n.º 15
0
    def test_fetch_all_candidates_from_api(self):
        self.election.delete()
        Election.fetch_all_from_api()
        election = Election.objects.all()[0]

        self.assertEquals(Candidate.objects.count(), 3)

        candidate = Candidate.objects.all()[0]
        self.assertEquals(candidate.remote_id,1)
        self.assertEquals(candidate.name, 'Juanito Perez')
        self.assertEquals(candidate.slug, 'juanito-perez')
        self.assertEquals(candidate.photo, '/media/photos/dummy.jpg')
        self.assertEquals(candidate.election, election)
Exemplo n.º 16
0
    def test_fetch_all_categories(self):
        Election.fetch_all_from_api()
        election = Election.objects.all()[0]

        self.assertEquals(Category.objects.count(), 2)

        categorie = Category.objects.all()[0]
        self.assertEqual(categorie.remote_id,1)
        self.assertEqual(categorie.name,'Politicas Publicas')
        self.assertEqual(categorie.order,1)
        self.assertEqual(categorie.resource_uri,'/api/v2/category/1/')
        self.assertEquals(categorie.slug,'politicas-publicas')
        self.assertEquals(categorie.election, election)
Exemplo n.º 17
0
    def test_it_does_not_create_replicate_answers(self):
        Election.fetch_all_from_api()
        UpdatingDataCandidator.install_candidator_yaml(yaml_file='candidator_example_data_updating')
        election = Election.objects.all()[0]
        election.update()
        questions = Question.objects.filter(category__election=election)

        #THERE ARE QUESTIONS ADDED BY DEFAULT TO CANDIDEIT.ORG
        #I HAVE TO FIX THIS IN ORDER TO COUNT
        #4 QUESTIONS AND
        #10 ANSWERS
        self.assertEquals(questions.count(), 6)
        answers = Answer.objects.filter(question__in=questions)

        self.assertEquals(answers.count(), 14)
Exemplo n.º 18
0
    def test_it_send_created_parameter_depending_for_updating(self):
        #defining the receiver
        def signal_receiver(sender, instance, created, **kwargs):
            if signal_receiver.times == 1:
                self.assertTrue(created)
            if signal_receiver.times == 2:
                self.assertFalse(created)


        signal_receiver = MethodCallLogger(signal_receiver)
        #connecting the thing
        election_finished.connect(signal_receiver)
        #creating
        Election.fetch_all_from_api()
        #updating
        Election.fetch_all_from_api()
Exemplo n.º 19
0
    def test_election_does_not_create_two_personal_data_candidates(self):
        Election.fetch_all_from_api()

        UpdatingDataCandidator.install_candidator_yaml(yaml_file='candidator_example_data_with_answers')

        election = Election.objects.all()[0]

        UpdatingDataCandidator.install_candidator_yaml(yaml_file='candidator_example_data_with_answers2')
        election.update()

        personaldata = election.personaldata_set.get(label=u'Profesion')
        candidate = election.candidate_set.get(name="Juanito Perez")


        personal_data_candidates = personaldata.personaldatacandidate_set.filter(candidate=candidate)
        self.assertEquals(personal_data_candidates.count(), 1)
Exemplo n.º 20
0
    def test_a_signal_is_called(self):

        #defining the receiver
        def signal_receiver(sender, instance, created, **kwargs):
            self.assertIsInstance(instance, Election)
            self.assertEquals(sender, Election)
            self.assertTrue(created)


        signal_receiver = MethodCallLogger(signal_receiver)
        #connecting the thing
        election_finished.connect(signal_receiver)

        Election.fetch_all_from_api()

        self.assertTrue(signal_receiver.was_called)
        self.assertEquals(signal_receiver.times, 1)
Exemplo n.º 21
0
    def test_election_update_answers(self):
        Election.fetch_all_from_api()
        juanito = Candidate.objects.all()[0]
        
        UpdatingDataCandidator.install_candidator_yaml(yaml_file='candidator_example_data_with_answers2')
        election = Election.objects.all()[0]
        election.update_answers()


        juanito = Candidate.objects.all()[0]

        self.assertEquals(juanito.answers.all().count(), 4)
        
        paros = Question.objects.get(question='Esta de a cuerdo con los paros?')
        self.assertEquals(juanito.answers.get(question=paros).caption, u'Estoy de acuerdo con algunos paros')
        
        marchas = Question.objects.get(question='Le gusta ir a las marchas?')
        self.assertEquals(juanito.answers.get(question=marchas).caption, u'Siempre')
        
        carretear = Question.objects.get(question='Quiere gastar su plata carreteando?')
        self.assertEquals(juanito.answers.get(question=carretear).caption, u'A veces')
        
        plata = Question.objects.get(question='Quiere robarse la plata del CEI?')
        self.assertEquals(juanito.answers.get(question=plata).caption, u'No')

        #now test with new information source
        information_source = InformationSource.objects.get(Q(question=paros) & Q(candidate=juanito))
        self.assertEquals(information_source.content, u'En el diario más cercano')


        tester = Candidate.objects.get(resource_uri='/api/v2/candidate/2/')
        information_source2 = InformationSource.objects.get(Q(question=paros) & Q(candidate=tester))
        self.assertEquals(information_source2.content, u'this IS did not exist before')

        personaldata = election.personaldata_set.get(label=u'Profesion')
        candidate = election.candidate_set.get(name="Juanito Perez")


        personal_data_candidates = personaldata.personaldatacandidate_set.filter(candidate=candidate)
        self.assertEquals(personal_data_candidates.count(), 1)
        self.assertEquals(personal_data_candidates[0].value, u"Grande")
Exemplo n.º 22
0
 def test_load_all_elections(self):
     Election.fetch_all_from_api()
     self.assertEquals(Election.objects.count(), 21)
Exemplo n.º 23
0
 def setUp(self):
     super(BackgroundCandidateTest, self).setUp()
     Election.fetch_all_from_api()
Exemplo n.º 24
0
 def test_it_gets_only_the_first_5_elections(self):
     Election.fetch_all_from_api(max_elections=5, offset=0)
     self.assertEquals(Election.objects.count(), 5)
Exemplo n.º 25
0
 def setUp(self):
     super(TemplateTagsTest, self).setUp()
     self.election = Election.fetch_all_from_api()
 def handle(self, *args, **options):
     Election.fetch_all_from_api()
 def handle(self, *args, **options):
     Election.fetch_all_from_api()