def test_deleta_casa(self):

    	partidoTest1 = models.Partido()
    	partidoTest1.nome = 'PA'
    	partidoTest1.numero = '01'
        partidoTest1.save()
        partidoTest2 = models.Partido()
    	partidoTest2.nome = 'PB'
    	partidoTest2.numero = '02'
        partidoTest2.save()
         
        parlamentarTest1 = models.Parlamentar()
    	parlamentarTest1.id_parlamentar = ''
    	parlamentarTest1.nome ='Pierre'
    	parlamentarTest1.genero = ''
        parlamentarTest1.save()
        parlamentarTest2 = models.Parlamentar()
    	parlamentarTest2.id_parlamentar = ''
    	parlamentarTest2.nome = 'Napoleao'
    	parlamentarTest2.genero = ''
        parlamentarTest2.save()
    	
        casa_legislativaTest1 = models.CasaLegislativa()
    	casa_legislativaTest1.nome= 'Casa1'
    	casa_legislativaTest1.nome_curto = 'cs1'
    	casa_legislativaTest1.esfera = 'FEDERAL'
        casa_legislativaTest1.local = ''
    	casa_legislativaTest1.atualizacao = '2012-06-01'
    	casa_legislativaTest1.save()
        casa_legislativaTest2 = models.CasaLegislativa()
    	casa_legislativaTest2.nome='Casa2'
    	casa_legislativaTest2.nome_curto='cs2'
    	casa_legislativaTest2.esfera = 'MUNICIPAL'
        casa_legislativaTest2.local = 'local2'
    	casa_legislativaTest2.atualizacao = '2012-12-31'
        casa_legislativaTest2.save()

    	legislaturaTest1 = models.Legislatura()
    	legislaturaTest1.parlamentar=parlamentarTest1
    	legislaturaTest1.casa_legislativa = casa_legislativaTest1
    	legislaturaTest1.inicio='2013-01-01'
    	legislaturaTest1.fim='2013-02-01'
    	legislaturaTest1.partido=partidoTest1
    	legislaturaTest1.localidade='PB'
    	legislaturaTest1.save()
    	legislaturaTest2 = models.Legislatura()
    	legislaturaTest2.parlamentar=parlamentarTest2
    	legislaturaTest2.casa_legislativa = casa_legislativaTest2
    	legislaturaTest2.inicio='2013-01-02'
    	legislaturaTest2.fim='2013-02-02'
    	legislaturaTest2.partido=partidoTest2
    	legislaturaTest2.localidade='PR'
    	legislaturaTest2.save()

    	proposicaoTest1= models.Proposicao()
    	proposicaoTest1.id_prop ='0001'
        proposicaoTest1.sigla = 'PR1'
        proposicaoTest1.numero = '0001'
        proposicaoTest1.ano = '2013'
        proposicaoTest1.data_apresentacao = '2013-01-02'
        proposicaoTest1.casa_legislativa = casa_legislativaTest1
    	proposicaoTest1.save()
    	proposicaoTest2= models.Proposicao()
    	proposicaoTest2.id_prop ='0002'
        proposicaoTest2.sigla = 'PR2'
        proposicaoTest2.numero = '0002'
        proposicaoTest2.ano = '2013'
        proposicaoTest2.data_apresentacao = '2013-02-02'
        proposicaoTest2.casa_legislativa = casa_legislativaTest2
    	proposicaoTest2.save()

    	votacaoTest1 = models.Votacao(id_vot = ' 12345',descricao = 'Teste da votacao',data = '1900-12-05',resultado = 'Teste',proposicao = 		proposicaoTest1)
    	votacaoTest1.save()		
      
      	votoTest1 = models.Voto(votacao = votacaoTest1,legislatura = legislaturaTest1,opcao = 'TESTE' )
      	votoTest1.save()
    	
    	antes_objetos_partido=models.Partido.objects.all()
    	antes_objetos_parlamentar=models.Parlamentar.objects.all()
    	antes_objetos_casa=models.CasaLegislativa.objects.all()
    	antes_objetos_legislatura=models.Legislatura.objects.all()
    	antes_objetos_proposicao=models.Proposicao.objects.all()
    	antes_objetos_voto=models.Voto.objects.all()
    	antes_objetos_votacao=models.Votacao.objects.all()

        nomes_partido = [p.nome for p in antes_objetos_partido]
        self.assertTrue('PA' in nomes_partido)
        self.assertTrue('PB' in nomes_partido)

        nomes_parlamentar = [pl.nome for pl in antes_objetos_parlamentar]
        self.assertTrue('Pierre' in nomes_parlamentar)
        self.assertTrue('Napoleao' in nomes_parlamentar)

    	nomes_casa = [c.nome for c in antes_objetos_casa]
        self.assertTrue('Casa1' in nomes_casa)
        self.assertTrue('Casa2' in nomes_casa)

    	nomes_legislatura = [l.localidade for l in antes_objetos_legislatura]
        self.assertTrue('PB' in nomes_legislatura)
        self.assertTrue('PR' in nomes_legislatura)

    	nomes_proposicao = [lg.sigla for lg in antes_objetos_proposicao]
        self.assertTrue('PR1' in nomes_proposicao)
        self.assertTrue('PR2' in nomes_proposicao)

    	nomes_voto = [v.votacao for v in antes_objetos_voto]
        self.assertTrue(votacaoTest1 in nomes_voto)

    	nomes_votacao = [vt.id_vot for vt in antes_objetos_votacao]
        self.assertTrue(' 12345' in nomes_votacao)

        
        models.CasaLegislativa.deleta_casa('casa_qualquer')#Tentando excluir uma casa que não existe
        models.CasaLegislativa.deleta_casa('cs1')
    	
        

        depois_objetos_partido=models.Partido.objects.all()
    	depois_objetos_parlamentar=models.Parlamentar.objects.all()
    	depois_objetos_casa=models.CasaLegislativa.objects.all()
    	depois_objetos_legislatura=models.Legislatura.objects.all()
    	depois_objetos_proposicao=models.Proposicao.objects.all()
    	depois_objetos_voto=models.Voto.objects.all()
    	depois_objetos_votacao=models.Votacao.objects.all()

    	nomes_partido = [p.nome for p in depois_objetos_partido]
        self.assertTrue('PA' in nomes_partido)
        self.assertTrue('PB' in nomes_partido)

    	nomes_parlamentar = [pl.nome for pl in depois_objetos_parlamentar]
        self.assertTrue('Pierre' in nomes_parlamentar)
        self.assertTrue('Napoleao' in nomes_parlamentar)

        nomes_casa = [c.nome for c in depois_objetos_casa]
        self.assertFalse('Casa1' in nomes_casa)
        self.assertTrue('Casa2' in nomes_casa)

    	nomes_legislatura = [l.localidade for l in depois_objetos_legislatura]
        self.assertFalse('PB' in nomes_legislatura)
        self.assertTrue('PR' in nomes_legislatura)

    	nomes_proposicao = [lg.sigla for lg in depois_objetos_proposicao]
        self.assertFalse('PR1' in nomes_proposicao)
        self.assertTrue('PR2' in nomes_proposicao)

    	nomes_voto = [v.votacao for v in depois_objetos_voto]
        self.assertFalse(votacaoTest1 in nomes_voto)

    	nomes_votacao = [vt.id_vot for vt in depois_objetos_votacao]
        self.assertFalse(' 12345' in nomes_votacao)
Exemple #2
0
    def test_remove_house(self):

        # Receives objects of Partido for inserting data to removal house test
        partyTest1 = models.Partido()

        partyTest1.nome = 'PA'
        partyTest1.numero = '01'
        partyTest1.cor = '#FFFAAA'
        partyTest1.save()

        # Receives objects of Partido for inserting data to removal house test
        partyTest2 = models.Partido()

        partyTest2.nome = 'PB'
        partyTest2.numero = '02'
        partyTest1.cor = '#FFFFFF'
        partyTest2.save()

        # Receives objects of Parlamentar for inserting data to removal house test
        parliamentaryTest1 = models.Parlamentar()

        parliamentaryTest1.id_parlamentar = ''
        parliamentaryTest1.nome = 'Pierre'
        parliamentaryTest1.genero = ''
        parliamentaryTest1.save()

        # Receives objects of Parlamentar for inserting data to removal house test
        parliamentaryTest2 = models.Parlamentar()

        parliamentaryTest2.id_parlamentar = ''
        parliamentaryTest2.nome = 'Napoleao'
        parliamentaryTest2.genero = ''
        parliamentaryTest2.save()

        # Receives objects of CasaLegislativa for inserting data to removal house test
        lesgilativeHouseTest1 = models.CasaLegislativa()

        lesgilativeHouseTest1.nome = 'Casa1'
        lesgilativeHouseTest1.nome_curto = 'cs1'
        lesgilativeHouseTest1.esfera = 'FEDERAL'
        lesgilativeHouseTest1.local = ''
        lesgilativeHouseTest1.atualizacao = '2012-06-01'
        lesgilativeHouseTest1.save()

        # Receives objects of CasaLegislativa for inserting data to removal house test
        lesgilativeHouseTest2 = models.CasaLegislativa()

        lesgilativeHouseTest2.nome = 'Casa2'
        lesgilativeHouseTest2.nome_curto = 'cs2'
        lesgilativeHouseTest2.esfera = 'MUNICIPAL'
        lesgilativeHouseTest2.local = 'local2'
        lesgilativeHouseTest2.atualizacao = '2012-12-31'
        lesgilativeHouseTest2.save()

        # Receives objects of Legislature for inserting data to removal house test
        legislatureTest1 = models.Legislatura()

        legislatureTest1.parlamentar = parliamentaryTest1
        legislatureTest1.casa_legislativa = lesgilativeHouseTest1
        legislatureTest1.inicio = '2013-01-01'
        legislatureTest1.fim = '2013-02-01'
        legislatureTest1.partido = partyTest1
        legislatureTest1.localidade = 'PB'
        legislatureTest1.save()

        # Receives objects of Legislature for inserting data to removal house test
        legislatureTest2 = models.Legislatura()

        legislatureTest2.parlamentar = parliamentaryTest2
        legislatureTest2.casa_legislativa = lesgilativeHouseTest2
        legislatureTest2.inicio = '2013-01-02'
        legislatureTest2.fim = '2013-02-02'
        legislatureTest2.partido = partyTest2
        legislatureTest2.localidade = 'PR'
        legislatureTest2.save()

        # Receives objects of Proposicao for inserting data to removal house test
        propositionTest1 = models.Proposicao()

        propositionTest1.id_prop = '0001'
        propositionTest1.sigla = 'PR1'
        propositionTest1.numero = '0001'
        propositionTest1.ano = '2013'
        propositionTest1.data_apresentacao = '2013-01-02'
        propositionTest1.casa_legislativa = lesgilativeHouseTest1
        propositionTest1.save()

        # Receives objects of Proposicao for inserting data to removal house test
        propositionTest2 = models.Proposicao()

        propositionTest2.id_prop = '0002'
        propositionTest2.sigla = 'PR2'
        propositionTest2.numero = '0002'
        propositionTest2.ano = '2013'
        propositionTest2.data_apresentacao = '2013-02-02'
        propositionTest2.casa_legislativa = lesgilativeHouseTest2
        propositionTest2.save()

        # Receives objects of Votaçao for inserting data to removal house test
        votingTest1 = models.Votacao(id_vot=' 12345',
                                     descricao='Teste da votacao',
                                     data='1900-12-05',
                                     resultado='Teste',
                                     proposicao=propositionTest1)

        votingTest1.save()

        # Receives objects of Votaçao for inserting data to removal house test
        voteTest1 = models.Voto(votacao=votingTest1,
                                legislatura=legislatureTest1,
                                opcao='TESTE')

        voteTest1.save()

        # Receives all objects of Partido from models before removal
        before_party_objects = models.Partido.objects.all()

        # Receives all objects of Parlamentar from models before removal
        before_parliamentary_objects = models.Parlamentar.objects.all()

        # Receives all objects of CasaLegislativa from models before removal
        before_house_objects = models.CasaLegislativa.objects.all()

        # Receives all objects of Legislatura from models before removal
        before_legislature_objects = models.Legislatura.objects.all()

        # Receives all objects of Proposicao from models before removal
        before_proposition_objects = models.Proposicao.objects.all()

        # Receives all objects of Voto from models before removal
        before_vote_objects = models.Voto.objects.all()

        # Receives all objects of Votacao from models before removal
        before_voting_objects = models.Votacao.objects.all()

        # Receives the names of partidos before removal
        party_names = [p.nome for p in before_party_objects]

        self.assertTrue('PA' in party_names)
        self.assertTrue('PB' in party_names)

        # Receives the names of parliamentaries before removal
        parliamentary_names = [pl.nome for pl in before_parliamentary_objects]

        self.assertTrue('Pierre' in parliamentary_names)
        self.assertTrue('Napoleao' in parliamentary_names)

        # Receives the names of houses before removal
        house_names = [c.nome for c in before_house_objects]

        self.assertTrue('Casa1' in house_names)
        self.assertTrue('Casa2' in house_names)

        # Receives the names of legislaturas before removal
        legislature_names = [l.localidade for l in before_legislature_objects]

        self.assertTrue('PB' in legislature_names)
        self.assertTrue('PR' in legislature_names)

        # Receives the names of ppropositions before removal
        proposition_names = [lg.sigla for lg in before_proposition_objects]

        self.assertTrue('PR1' in proposition_names)
        self.assertTrue('PR2' in proposition_names)

        # Receives the names of votes before removal
        vote_names = [v.votacao for v in before_vote_objects]

        self.assertTrue(votingTest1 in vote_names)

        # Receives the names of voting before removal
        voting_names = [vt.id_vot for vt in before_voting_objects]

        self.assertTrue(' 12345' in voting_names)

        # Trying to delete a house that does not exist
        models.CasaLegislativa.remove_house('casa_qualquer')
        models.CasaLegislativa.remove_house('cs1')

        # Receives all objects of Partido from models after removal
        after_party_objects = models.Partido.objects.all()

        # Receives all objects of Parlamentar from models after removal
        after_parliamentary_objects = models.Parlamentar.objects.all()

        # Receives all objects of CasaLegislativa from models after removal
        after_house_objects = models.CasaLegislativa.objects.all()

        # Receives all objects of Legislatura from models after removal
        after_legislature_objects = models.Legislatura.objects.all()

        # Receives all objects of Propositcao from models after removal
        after_proposition_objects = models.Proposicao.objects.all()

        # Receives all objects of Voto from models after removal
        after_vote_objects = models.Voto.objects.all()

        # Receives all objects of Votacao from models after removal
        after_voting_objects = models.Votacao.objects.all()

        # Receives the names of partidos after removal
        party_names = [p.nome for p in after_party_objects]

        self.assertTrue('PA' in party_names)
        self.assertTrue('PB' in party_names)

        # Receives the names of parliamentaries after removal
        parliamentary_names = [pl.nome for pl in after_parliamentary_objects]

        self.assertTrue('Pierre' in parliamentary_names)
        self.assertTrue('Napoleao' in parliamentary_names)

        # Receives the names of houses after removal
        house_names = [c.nome for c in after_house_objects]

        self.assertFalse('Casa1' in house_names)
        self.assertTrue('Casa2' in house_names)

        # Receives the names of legislaturas after removal
        legislature_names = [l.localidade for l in after_legislature_objects]

        self.assertFalse('PB' in legislature_names)
        self.assertTrue('PR' in legislature_names)

        # Receives the names of propositions after removal
        proposition_names = [lg.sigla for lg in after_proposition_objects]

        self.assertFalse('PR1' in proposition_names)
        self.assertTrue('PR2' in proposition_names)

        # Receives the names of votes after removal
        vote_names = [v.votacao for v in after_vote_objects]

        self.assertFalse(votingTest1 in vote_names)

        # Receives the names of voting after removal
        voting_names = [vt.id_vot for vt in after_voting_objects]

        self.assertFalse(' 12345' in voting_names)