committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 347 additions and 32 deletions
-
2.travis.yml
-
19pytrustnfe/nfse/paulistana/templates/EnvioLoteRPS.xml
-
60pytrustnfe/nfse/paulistana/templates/EnvioRPS.xml
-
6setup.py
-
10tests/XMLs/paulistana_signature.xml
-
1tests/XMLs/xml_send_rps_batch_to_paulistana.xml
-
56tests/const.py
-
35tests/test_nfse_paulistana_email_tomador.py
-
54tests/test_nfse_paulistana_endereco_tomador.py
-
29tests/test_nfse_paulistana_para_lote.py
-
60tests/test_nfse_paulistana_tipo_cpfcnpj.py
-
47tests/test_nfse_paulistana_valores_default.py
1
tests/XMLs/xml_send_rps_batch_to_paulistana.xml
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,56 @@ |
|||||
|
LOTE_RPS = [ |
||||
|
{ |
||||
|
'assinatura': '123', |
||||
|
'serie': '1', |
||||
|
'numero': str(i), |
||||
|
'data_emissao': '2016-08-29', |
||||
|
'codigo_atividade': '07498', |
||||
|
'total_servicos': '2.00', |
||||
|
'total_deducoes': '3.00', |
||||
|
'prestador': { |
||||
|
'inscricao_municipal': '123456' |
||||
|
}, |
||||
|
'tomador': { |
||||
|
'tipo_cpfcnpj': 1, |
||||
|
'cpf_cnpj': '12345678923256', |
||||
|
'inscricao_municipal': '123456', |
||||
|
'razao_social': 'Trustcode', |
||||
|
'tipo_logradouro': '1', |
||||
|
'complemento': 'aaa', |
||||
|
'logradouro': 'Vinicius de Moraes, 42', |
||||
|
'numero': '42', |
||||
|
'bairro': 'Corrego', |
||||
|
'cidade': 'Floripa', |
||||
|
'uf': 'SC', |
||||
|
'cep': '88037240', |
||||
|
'email': 'user@user.com' |
||||
|
}, |
||||
|
'codigo_atividade': '07498', |
||||
|
'aliquota_atividade': '5.00', |
||||
|
'descricao': 'Venda de servico' |
||||
|
} for i in range(5) |
||||
|
] |
||||
|
|
||||
|
DEFAULT_RPS = [ |
||||
|
{ |
||||
|
'assinatura': '123', |
||||
|
'serie': '1', |
||||
|
'numero': '1', |
||||
|
'data_emissao': '2016-08-29', |
||||
|
'codigo_atividade': '07498', |
||||
|
'prestador': { |
||||
|
'inscricao_municipal': '123456' |
||||
|
}, |
||||
|
'tomador': { |
||||
|
'tipo_cpfcnpj': 1, |
||||
|
'cpf_cnpj': '12345678923256', |
||||
|
}, |
||||
|
} |
||||
|
] |
||||
|
|
||||
|
NFSE = { |
||||
|
'cpf_cnpj': '12345678901234', |
||||
|
'data_inicio': '2016-08-29', |
||||
|
'data_fim': '2016-08-29', |
||||
|
'lista_rps': [] |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
# coding=utf-8 |
||||
|
|
||||
|
import unittest |
||||
|
from pytrustnfe.xml import render_xml, sanitize_response |
||||
|
from tests.const import NFSE, DEFAULT_RPS |
||||
|
|
||||
|
template_path = 'pytrustnfe/nfse/paulistana/templates' |
||||
|
|
||||
|
|
||||
|
def _get_nfse(lista_rps): |
||||
|
nfse = NFSE |
||||
|
nfse['lista_rps'] = lista_rps |
||||
|
return nfse |
||||
|
|
||||
|
|
||||
|
def get_objects(nfse): |
||||
|
xml_rps = render_xml(template_path, 'EnvioRPS.xml', False, nfse=nfse) |
||||
|
_, obj_rps = sanitize_response(xml_rps) |
||||
|
|
||||
|
xml_lote_rps = render_xml(template_path, 'EnvioLoteRPS.xml', False, nfse=nfse) |
||||
|
_, obj_lote_rps = sanitize_response(xml_lote_rps) |
||||
|
|
||||
|
return obj_rps, obj_lote_rps |
||||
|
|
||||
|
|
||||
|
class test_nfse_paulistana_email_tomador(unittest.TestCase): |
||||
|
|
||||
|
def test_rps_sem_email(self): |
||||
|
nfse = _get_nfse(DEFAULT_RPS) |
||||
|
|
||||
|
obj_rps, obj_lote_rps = get_objects(nfse) |
||||
|
|
||||
|
self.assertFalse(hasattr(obj_rps.RPS, 'EmailTomador')) |
||||
|
self.assertFalse(hasattr(obj_lote_rps.RPS, 'EmailTomador')) |
||||
|
|
||||
@ -0,0 +1,54 @@ |
|||||
|
# coding=utf-8 |
||||
|
|
||||
|
import unittest |
||||
|
from pytrustnfe.xml import render_xml, sanitize_response |
||||
|
from tests.const import NFSE, DEFAULT_RPS |
||||
|
|
||||
|
|
||||
|
attrs = ['TipoLogradouro', 'Logradouro', 'NumeroEndereco', 'ComplementoEndereco', 'Bairro', 'CEP'] |
||||
|
|
||||
|
template_path = 'pytrustnfe/nfse/paulistana/templates' |
||||
|
|
||||
|
|
||||
|
def _get_nfse(lista_rps): |
||||
|
nfse = NFSE |
||||
|
nfse['lista_rps'] = lista_rps |
||||
|
return nfse |
||||
|
|
||||
|
|
||||
|
def get_objects(nfse): |
||||
|
xml_rps = render_xml(template_path, 'EnvioRPS.xml', False, nfse=nfse) |
||||
|
_, obj_rps = sanitize_response(xml_rps) |
||||
|
|
||||
|
xml_lote_rps = render_xml(template_path, 'EnvioLoteRPS.xml', False, nfse=nfse) |
||||
|
_, obj_lote_rps = sanitize_response(xml_lote_rps) |
||||
|
|
||||
|
return obj_rps, obj_lote_rps |
||||
|
|
||||
|
|
||||
|
class test_nfse_paulistana_endereco_tomador(unittest.TestCase): |
||||
|
|
||||
|
def test_rps_sem_cidade(self): |
||||
|
nfse = _get_nfse(DEFAULT_RPS) |
||||
|
|
||||
|
obj_rps, obj_lote_rps = get_objects(nfse) |
||||
|
|
||||
|
self.assertFalse(hasattr(obj_rps.RPS, 'EnderecoTomador')) |
||||
|
self.assertFalse(hasattr(obj_lote_rps.RPS, 'EnderecoTomador')) |
||||
|
|
||||
|
def test_rps_sem_dados_endereco(self): |
||||
|
lista_rps = DEFAULT_RPS |
||||
|
|
||||
|
for rps in lista_rps: |
||||
|
rps['tomador']['cidade'] = 'Florianópolis' |
||||
|
|
||||
|
nfse = _get_nfse(lista_rps) |
||||
|
|
||||
|
obj_rps, obj_lote_rps = get_objects(nfse) |
||||
|
|
||||
|
self.assertTrue(hasattr(obj_rps.RPS, 'EnderecoTomador')) |
||||
|
self.assertTrue(hasattr(obj_lote_rps.RPS, 'EnderecoTomador')) |
||||
|
|
||||
|
for attr in attrs: |
||||
|
self.assertFalse(hasattr(obj_rps.RPS.EnderecoTomador, attr)) |
||||
|
self.assertFalse(hasattr(obj_lote_rps.RPS.EnderecoTomador, attr)) |
||||
@ -0,0 +1,29 @@ |
|||||
|
# coding=utf-8 |
||||
|
|
||||
|
import os.path |
||||
|
import unittest |
||||
|
from pytrustnfe.xml import render_xml, sanitize_response |
||||
|
from tests.const import LOTE_RPS, NFSE |
||||
|
|
||||
|
|
||||
|
def _get_nfse(): |
||||
|
nfse = NFSE |
||||
|
nfse['lista_rps'] = LOTE_RPS |
||||
|
return nfse |
||||
|
|
||||
|
|
||||
|
class test_nfse_paulistana_para_lote(unittest.TestCase): |
||||
|
xml_path = os.path.join(os.path.dirname(__file__), 'XMLs') |
||||
|
template_path = 'pytrustnfe/nfse/paulistana/templates' |
||||
|
BATCH_SIZE = len(LOTE_RPS) |
||||
|
|
||||
|
def test_envio_nfse(self): |
||||
|
nfse = _get_nfse() |
||||
|
|
||||
|
xml_send = render_xml(self.template_path, 'EnvioLoteRPS.xml', False, nfse=nfse) |
||||
|
expected_xml = open(os.path.join(self.xml_path, 'xml_send_rps_batch_to_paulistana.xml'), 'r').read() |
||||
|
|
||||
|
_, obj = sanitize_response(xml_send) |
||||
|
|
||||
|
self.assertEqual(obj.Cabecalho.QtdRPS, self.BATCH_SIZE) |
||||
|
self.assertEqual(xml_send, expected_xml) |
||||
@ -0,0 +1,60 @@ |
|||||
|
# coding=utf-8 |
||||
|
|
||||
|
import os.path |
||||
|
import unittest |
||||
|
from pytrustnfe.xml import render_xml, sanitize_response |
||||
|
from tests.const import DEFAULT_RPS, NFSE |
||||
|
|
||||
|
template_path = 'pytrustnfe/nfse/paulistana/templates' |
||||
|
|
||||
|
|
||||
|
def _get_nfse(tipo_cpfcnpj): |
||||
|
nfse = NFSE |
||||
|
lista_rps = DEFAULT_RPS |
||||
|
|
||||
|
for rps in lista_rps: |
||||
|
rps['tomador']['tipo_cpfcnpj'] = tipo_cpfcnpj |
||||
|
rps['tomador']['cpf_cnpj'] = '12345678923256' |
||||
|
|
||||
|
nfse['lista_rps'] = lista_rps |
||||
|
return nfse |
||||
|
|
||||
|
|
||||
|
def get_objects(nfse): |
||||
|
xml_rps = render_xml(template_path, 'EnvioRPS.xml', False, nfse=nfse) |
||||
|
_, obj_rps = sanitize_response(xml_rps) |
||||
|
|
||||
|
xml_lote_rps = render_xml(template_path, 'EnvioLoteRPS.xml', False, nfse=nfse) |
||||
|
_, obj_lote_rps = sanitize_response(xml_lote_rps) |
||||
|
|
||||
|
return obj_rps, obj_lote_rps |
||||
|
|
||||
|
|
||||
|
class test_nfse_paulistana_tipo_cpfcnpj(unittest.TestCase): |
||||
|
|
||||
|
def test_tipo_cpfcnpj_1(self): |
||||
|
nfse = _get_nfse(tipo_cpfcnpj=1) |
||||
|
|
||||
|
obj_rps, obj_lote_rps = get_objects(nfse) |
||||
|
|
||||
|
self.assertTrue(hasattr(obj_rps.RPS, 'CPFCNPJTomador')) |
||||
|
self.assertTrue(hasattr(obj_rps.RPS.CPFCNPJTomador, 'CPF')) |
||||
|
self.assertTrue(hasattr(obj_lote_rps.RPS, 'CPFCNPJTomador')) |
||||
|
self.assertTrue(hasattr(obj_lote_rps.RPS.CPFCNPJTomador, 'CPF')) |
||||
|
|
||||
|
def test_tipo_cpfcnpj_2(self): |
||||
|
nfse = _get_nfse(tipo_cpfcnpj=2) |
||||
|
|
||||
|
obj_rps, obj_lote_rps = get_objects(nfse) |
||||
|
|
||||
|
self.assertTrue(hasattr(obj_rps.RPS, 'CPFCNPJTomador')) |
||||
|
self.assertTrue(hasattr(obj_rps.RPS.CPFCNPJTomador, 'CNPJ')) |
||||
|
self.assertTrue(hasattr(obj_lote_rps.RPS, 'CPFCNPJTomador')) |
||||
|
self.assertTrue(hasattr(obj_lote_rps.RPS.CPFCNPJTomador, 'CNPJ')) |
||||
|
|
||||
|
def test_tipo_cpfcnpj_3(self): |
||||
|
nfse = _get_nfse(tipo_cpfcnpj=3) |
||||
|
|
||||
|
obj_rps, obj_lote_rps = get_objects(nfse) |
||||
|
|
||||
|
self.assertFalse(hasattr(obj_rps.RPS, 'CPFCNPJTomador')) |
||||
@ -0,0 +1,47 @@ |
|||||
|
# coding=utf-8 |
||||
|
|
||||
|
import os.path |
||||
|
import unittest |
||||
|
from pytrustnfe.xml import render_xml, sanitize_response |
||||
|
from tests.const import DEFAULT_RPS, NFSE |
||||
|
|
||||
|
default_values = { |
||||
|
'TipoRPS': 'RPS', |
||||
|
'TributacaoRPS': 'T', |
||||
|
'ValorCOFINS': 0.0, |
||||
|
'ValorINSS': 0.0, |
||||
|
'ValorIR': 0.0, |
||||
|
'ValorPIS': 0.0, |
||||
|
'ValorCSLL': 0.0, |
||||
|
'ISSRetido': False |
||||
|
} |
||||
|
attrs = ['TipoRPS', 'TributacaoRPS', 'ValorPIS', 'ValorCOFINS', 'ValorINSS', 'ValorIR', 'ValorCSLL', 'ISSRetido'] |
||||
|
|
||||
|
|
||||
|
def _get_nfse(): |
||||
|
nfse = NFSE |
||||
|
nfse['lista_rps'] = DEFAULT_RPS |
||||
|
return nfse |
||||
|
|
||||
|
|
||||
|
class test_nfse_paulistana_valores_default(unittest.TestCase): |
||||
|
template_path = 'pytrustnfe/nfse/paulistana/templates' |
||||
|
xml_path = os.path.join(os.path.dirname(__file__), 'XMLs') |
||||
|
nfse = _get_nfse() |
||||
|
|
||||
|
def test_rps_sem_valores(self): |
||||
|
|
||||
|
xml_rps = render_xml(self.template_path, 'EnvioRPS.xml', False, nfse=self.nfse) |
||||
|
|
||||
|
_, obj = sanitize_response(xml_rps) |
||||
|
|
||||
|
for attr in attrs: |
||||
|
self.assertEqual(getattr(obj.RPS, attr), default_values[attr]) |
||||
|
|
||||
|
def test_lote_rps_sem_valores(self): |
||||
|
xml_lote_rps = render_xml(self.template_path, 'EnvioLoteRPS.xml', False, nfse=self.nfse) |
||||
|
|
||||
|
_, obj = sanitize_response(xml_lote_rps) |
||||
|
|
||||
|
for attr in attrs: |
||||
|
self.assertEqual(getattr(obj.RPS, attr), default_values[attr]) |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue