diff --git a/pytrustnfe/nfse/betha/__init__.py b/pytrustnfe/nfse/betha/__init__.py
index f2517fa..d700e6c 100644
--- a/pytrustnfe/nfse/betha/__init__.py
+++ b/pytrustnfe/nfse/betha/__init__.py
@@ -32,10 +32,10 @@ def _send(certificado, method, **kwargs):
sign_tag(certificado, **kwargs)
if kwargs['ambiente'] == 'producao':
+ url = 'http://e-gov.betha.com.br/e-nota-contribuinte-ws/nfseWS?wsdl'
+ else:
url = \
'http://e-gov.betha.com.br/e-nota-contribuinte-test-ws/nfseWS?wsdl'
- else:
- url = 'http://e-gov.betha.com.br/e-nota-contribuinte-ws/nfseWS?wsdl'
xml_send = render_xml(path, '%s.xml' % method, False, **kwargs)
@@ -105,7 +105,7 @@ def consultar_nfse_servico_tomado(certificado, **kwargs):
return _send(certificado, 'ConsultarNfseServicoTomado', **kwargs)
-def consulta_nfse_faixe(certificado, **kwargs):
+def consulta_nfse_faixa(certificado, **kwargs):
return _send(certificado, 'ConsultarNfseFaixa', **kwargs)
diff --git a/pytrustnfe/nfse/betha/templates/GerarNfse.xml b/pytrustnfe/nfse/betha/templates/GerarNfse.xml
index fdd22d1..536da09 100644
--- a/pytrustnfe/nfse/betha/templates/GerarNfse.xml
+++ b/pytrustnfe/nfse/betha/templates/GerarNfse.xml
@@ -1,3 +1,3 @@
- {% include 'rps.xml' %}
+ {% include 'Rps.xml' %}
diff --git a/pytrustnfe/nfse/betha/templates/RecepcionarLoteRps.xml b/pytrustnfe/nfse/betha/templates/RecepcionarLoteRps.xml
index 0b11051..eeaeb98 100644
--- a/pytrustnfe/nfse/betha/templates/RecepcionarLoteRps.xml
+++ b/pytrustnfe/nfse/betha/templates/RecepcionarLoteRps.xml
@@ -7,7 +7,7 @@
123498
1
- {% include 'rps.xml' %}
+ {% include 'Rps.xml' %}
diff --git a/pytrustnfe/nfse/betha/templates/RecepcionarLoteRpsSincrono.xml b/pytrustnfe/nfse/betha/templates/RecepcionarLoteRpsSincrono.xml
index 79f6eda..0bbf18d 100644
--- a/pytrustnfe/nfse/betha/templates/RecepcionarLoteRpsSincrono.xml
+++ b/pytrustnfe/nfse/betha/templates/RecepcionarLoteRpsSincrono.xml
@@ -7,7 +7,7 @@
123498
1
- {% include 'rps.xml' %}
+ {% include 'Rps.xml' %}
diff --git a/pytrustnfe/nfse/betha/templates/SubstituirNfse.xml b/pytrustnfe/nfse/betha/templates/SubstituirNfse.xml
index 294c0d0..ae6ab25 100644
--- a/pytrustnfe/nfse/betha/templates/SubstituirNfse.xml
+++ b/pytrustnfe/nfse/betha/templates/SubstituirNfse.xml
@@ -13,6 +13,6 @@
2
- {% include 'rps.xml' %}
+ {% include 'Rps.xml' %}
diff --git a/pytrustnfe/test/test_nfse_betha.py b/pytrustnfe/test/test_nfse_betha.py
new file mode 100644
index 0000000..6d7d721
--- /dev/null
+++ b/pytrustnfe/test/test_nfse_betha.py
@@ -0,0 +1,118 @@
+# coding=utf-8
+
+import mock
+import os.path
+import unittest
+from pytrustnfe.certificado import Certificado
+from pytrustnfe.nfse.betha import envio_lote_rps
+from pytrustnfe.nfse.betha import cancelar_nfse
+
+
+class test_nfse_betha(unittest.TestCase):
+
+ caminho = os.path.dirname(__file__)
+
+ def _get_nfse(self):
+ rps = [
+ {
+ 'assinatura': '123',
+ 'serie': '1',
+ 'numero': '1',
+ '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',
+ 'logradouro': 'Vinicius de Moraes, 42',
+ 'numero': '42',
+ 'bairro': 'Corrego',
+ 'cidade': 'Floripa',
+ 'uf': 'SC',
+ 'cep': '88037240',
+ },
+ 'codigo_atividade': '07498',
+ 'aliquota_atividade': '5.00',
+ 'descricao': 'Venda de servico'
+ }
+ ]
+ nfse = {
+ 'cpf_cnpj': '12345678901234',
+ 'data_inicio': '2016-08-29',
+ 'data_fim': '2016-08-29',
+ 'lista_rps': rps,
+ 'ambiente': 'homologacao',
+ }
+ return nfse
+
+ def test_envio_nfse_lote(self):
+ pfx_source = open(os.path.join(self.caminho, 'teste.pfx'), 'r').read()
+ pfx = Certificado(pfx_source, '123456')
+ nfse = self._get_nfse()
+
+ retorno = envio_lote_rps(pfx, nfse=nfse, ambiente='homologacao')
+
+ self.assertEqual(retorno['object'].Cabecalho.Sucesso, True)
+ self.assertEqual(
+ 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',
+ 'ambiente': 'homologacao',
+ }
+
+ 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.betha.get_authenticated_client') as client:
+ retorno = mock.MagicMock()
+ client.return_value = retorno
+ retorno.service.CancelarNfse.return_value = xml_return
+
+ retorno = cancelar_nfse(pfx, cancelamento=cancelamento,
+ ambiente='homologacao')
+
+ 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.betha.get_authenticated_client') as client:
+ retorno = mock.MagicMock()
+ client.return_value = retorno
+ retorno.service.CancelarNfse.return_value = xml_return
+
+ retorno = cancelar_nfse(pfx, cancelamento=cancelamento,
+ ambiente='homologacao')
+
+ self.assertEqual(retorno['received_xml'], xml_return)
+ self.assertEqual(retorno['object'].Cabecalho.Sucesso, False)
+ self.assertEqual(
+ retorno['object'].Erro.ChaveNFe.NumeroNFe, 446)