Skip to content

Commit

Permalink
Teste de cancelamento da NFse
Browse files Browse the repository at this point in the history
  • Loading branch information
danimaribeiro committed Sep 17, 2016
1 parent e876f02 commit 0790575
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions pytrustnfe/test/XMLs/paulistana_canc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><RetornoCancelamentoNFe xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.prefeitura.sp.gov.br/nfe"><Cabecalho Versao="1" xmlns=""><Sucesso>false</Sucesso></Cabecalho><Erro xmlns=""><Codigo>1305</Codigo><Descricao>Assinatura de cancelamento da NFS-e incorreta.</Descricao><ChaveNFe><InscricaoPrestador>512382</InscricaoPrestador><NumeroNFe>446</NumeroNFe><CodigoVerificacao>APRMJR</CodigoVerificacao></ChaveNFe></Erro></RetornoCancelamentoNFe>
1 change: 1 addition & 0 deletions pytrustnfe/test/XMLs/paulistana_canc_errado.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><RetornoCancelamentoNFe xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.prefeitura.sp.gov.br/nfe"><Cabecalho Versao="1" xmlns=""><Sucesso>false</Sucesso></Cabecalho><Erro xmlns=""><Codigo>1305</Codigo><Descricao>Assinatura de cancelamento da NFS-e incorreta.</Descricao><ChaveNFe><InscricaoPrestador>51212382</InscricaoPrestador><NumeroNFe>446</NumeroNFe><CodigoVerificacao>APR9QMJR</CodigoVerificacao></ChaveNFe></Erro></RetornoCancelamentoNFe>
1 change: 1 addition & 0 deletions pytrustnfe/test/XMLs/paulistana_canc_ok.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><RetornoCancelamentoNFe xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.prefeitura.sp.gov.br/nfe"><Cabecalho Versao="1" xmlns=""><Sucesso>true</Sucesso></Cabecalho></RetornoCancelamentoNFe>
50 changes: 50 additions & 0 deletions pytrustnfe/test/test_nfse_paulistana.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import unittest
from pytrustnfe.certificado import Certificado
from pytrustnfe.nfse.paulistana import envio_lote_rps
from pytrustnfe.nfse.paulistana import cancelamento_nfe


class test_nfse_paulistana(unittest.TestCase):
Expand Down Expand Up @@ -68,3 +69,52 @@ def test_envio_nfse(self):
retorno['object'].ChaveNFeRPS.ChaveNFe.NumeroNFe, 446)
self.assertEqual(
retorno['object'].ChaveNFeRPS.ChaveRPS.NumeroRPS, 6)

def _get_cancelamento(self):
return {
'cnpj_remetente': '123',
'assinatura': 'assinatura',
'numero_nfse': '456',
'inscricao_municipal': '654',
'codigo_verificacao': '789',
}

def test_cancelamento_nfse_ok(self):
pfx_source = open(os.path.join(self.caminho, 'teste.pfx'), 'r').read()
pfx = Certificado(pfx_source, '123456')
cancelamento = self._get_cancelamento()

path = os.path.join(os.path.dirname(__file__), 'XMLs')
xml_return = open(os.path.join(
path, 'paulistana_canc_ok.xml'), 'r').read()

with mock.patch('pytrustnfe.nfse.paulistana.get_authenticated_client') as client:
retorno = mock.MagicMock()
client.return_value = retorno
retorno.service.CancelamentoNFe.return_value = xml_return

retorno = cancelamento_nfe(pfx, cancelamento=cancelamento)

self.assertEqual(retorno['received_xml'], xml_return)
self.assertEqual(retorno['object'].Cabecalho.Sucesso, True)

def test_cancelamento_nfse_com_erro(self):
pfx_source = open(os.path.join(self.caminho, 'teste.pfx'), 'r').read()
pfx = Certificado(pfx_source, '123456')
cancelamento = self._get_cancelamento()

path = os.path.join(os.path.dirname(__file__), 'XMLs')
xml_return = open(os.path.join(
path, 'paulistana_canc_errado.xml'), 'r').read()

with mock.patch('pytrustnfe.nfse.paulistana.get_authenticated_client') as client:
retorno = mock.MagicMock()
client.return_value = retorno
retorno.service.CancelamentoNFe.return_value = xml_return

retorno = cancelamento_nfe(pfx, cancelamento=cancelamento)

self.assertEqual(retorno['received_xml'], xml_return)
self.assertEqual(retorno['object'].Cabecalho.Sucesso, False)
self.assertEqual(
retorno['object'].Erro.ChaveNFe.NumeroNFe, 446)

0 comments on commit 0790575

Please sign in to comment.