Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

[GINFES][master] auto #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/ginfes/generatedsnamespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,19 @@
"EnviarLoteRpsEnvio": 'xmlns="http://www.ginfes.com.br/servico_enviar_lote_rps_envio_v03.xsd" xmlns:tipos="http://www.ginfes.com.br/tipos_v03.xsd"',
"ListaRpsType": 'xmlns="http://www.ginfes.com.br/tipos_v03.xsd"',
"ConsultarSituacaoLoteRpsEnvio": 'xmlns="http://www.ginfes.com.br/servico_consultar_situacao_lote_rps_envio_v03.xsd" xmlns:tipos="http://www.ginfes.com.br/tipos_v03.xsd"',
"ConsultarNfseRpsEnvio": 'xmlns="http://www.ginfes.com.br/servico_consultar_nfse_rps_envio_v03.xsd" xmlns:tipos="http://www.ginfes.com.br/tipos_v03.xsd"',
"CancelarNfseEnvio": 'xmlns:p="http://www.ginfes.com.br/servico_cancelar_nfse_envio_v03.xsd" xmlns:p1="http://www.ginfes.com.br/tipos_v03.xsd"',
# "tcPedidoCancelamento": 'xmlns=""',
"cabecalho": 'xmlns:ns2="http://www.ginfes.com.br/cabecalho_v03.xsd"',
}

GenerateDSNamespaceTypePrefixes = {
"tcLoteRps": 'tipos',
"tcIdentificacaoPrestador": 'tipos',
"tcIdentificacaoRps": 'tipos',
"tcIdentificacaoNfse": 'p1',
"tcInfPedidoCancelamento": 'p1',
"tcPedidoCancelamento": 'p1',
"CancelarNfseEnvio": 'p',
"cabecalho": 'ns2'
}
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_nfselib_ginfes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<ConsultarNfseRpsEnvio
xmlns="http://www.ginfes.com.br/servico_consultar_nfse_rps_envio_v03.xsd"
xmlns:tipos="http://www.ginfes.com.br/tipos_v03.xsd">
<IdentificacaoRps>
<tipos:Numero>248</tipos:Numero>
<tipos:Serie>001</tipos:Serie>
<tipos:Tipo>1</tipos:Tipo>
</IdentificacaoRps>
<Prestador>
<tipos:Cnpj>23130935000198</tipos:Cnpj>
<tipos:InscricaoMunicipal>35172</tipos:InscricaoMunicipal>
</Prestador>
</ConsultarNfseRpsEnvio>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<EnviarLoteRpsEnvio xmlns="http://www.ginfes.com.br/servico_enviar_lote_rps_envio_v03.xsd" xmlns:tipos="http://www.ginfes.com.br/tipos_v03.xsd">
<LoteRps>
<tipos:Cnpj>59594315000157</tipos:Cnpj>
<tipos:InscricaoMunicipal>35172</tipos:InscricaoMunicipal>
<tipos:QuantidadeRps>1</tipos:QuantidadeRps>
<ListaRps xmlns="http://www.ginfes.com.br/tipos_v03.xsd">
<Rps>
<InfRps Id="rps50">
<IdentificacaoRps>
<Numero>50</Numero>
<Serie>001</Serie>
<Tipo>1</Tipo>
</IdentificacaoRps>
<DataEmissao>2020-06-04T13:58:46</DataEmissao>
<NaturezaOperacao>1</NaturezaOperacao>
<RegimeEspecialTributacao>1</RegimeEspecialTributacao>
<OptanteSimplesNacional>1</OptanteSimplesNacional>
<IncentivadorCultural>2</IncentivadorCultural>
<Status>1</Status>
<Servico>
<Valores>
<ValorServicos>100</ValorServicos>
<ValorDeducoes>0</ValorDeducoes>
<ValorPis>0</ValorPis>
<ValorCofins>0</ValorCofins>
<ValorInss>0</ValorInss>
<ValorIr>0</ValorIr>
<ValorCsll>0</ValorCsll>
<IssRetido>2</IssRetido>
<ValorIss>5</ValorIss>
<ValorIssRetido>0</ValorIssRetido>
<OutrasRetencoes>0</OutrasRetencoes>
<BaseCalculo>100</BaseCalculo>
<Aliquota>0.05</Aliquota>
<ValorLiquidoNfse>100</ValorLiquidoNfse>
</Valores>
<ItemListaServico>105</ItemListaServico>
<CodigoCnae>3101200</CodigoCnae>
<CodigoTributacaoMunicipio>6311900</CodigoTributacaoMunicipio>
<Discriminacao>[ODOO_DEV] Customized Odoo Development</Discriminacao>
<CodigoMunicipio>3132404</CodigoMunicipio>
</Servico>
<Prestador>
<tipos:Cnpj>59594315000157</tipos:Cnpj>
<tipos:InscricaoMunicipal>35172</tipos:InscricaoMunicipal>
</Prestador>
<Tomador>
<IdentificacaoTomador>
<CpfCnpj>
<Cnpj>81493979000189</Cnpj>
</CpfCnpj>
</IdentificacaoTomador>
<RazaoSocial>Cliente 1 SP</RazaoSocial>
<Endereco>
<Endereco>Rua Samuel Morse</Endereco>
<Numero>135</Numero>
<Bairro>Brooklin</Bairro>
<CodigoMunicipio>3550308</CodigoMunicipio>
<Uf>SP</Uf>
<Cep>4576060</Cep>
</Endereco>
</Tomador>
</InfRps>
</Rps>
</ListaRps>
</LoteRps>
</EnviarLoteRpsEnvio>
66 changes: 66 additions & 0 deletions tests/test_nfselib_ginfes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2020 - KMEE

import os
import sys
from os import path
from xmldiff import main
from lxml import etree as etree_
sys.path.append(path.join(path.dirname(__file__), '..', 'nfselib'))
from nfselib.ginfes.v3_01 import(
servico_enviar_lote_rps_envio,
servico_consultar_nfse_rps_envio,
)


def parsexml_(infile, parser=None, keep_signature=False, **kwargs):
if parser is None:
# Use the lxml ElementTree compatible parser so that, e.g.,
# we ignore comments.
parser = etree_.ETCompatXMLParser()
doc = etree_.parse(infile, parser=parser, **kwargs)
root = doc.getroot()
# remove Signature element before XML comparison
if not keep_signature:
for child in root:
if child.tag in ["{http://www.w3.org/2000/09/xmldsig#}Signature",
"{http://www.w3.org/2000/09/xmldsig#}\
ds:Signature"]:
root.remove(child)
subtree = etree_.ElementTree(root)
return subtree

def parse(inFilename, supermod):
parser = None
doc = parsexml_(inFilename, parser)
rootNode = doc.getroot()
rootTag, rootClass = supermod.get_root_tag(rootNode)
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
return rootObj

def execute_test(path, servico):
for filename in os.listdir(path):
subtree = parsexml_('%s/%s' % (path, filename,))
inputfile = 'input.xml'
subtree.write(inputfile, encoding='utf-8')

obj = parse(inputfile, servico)

outputfile = 'output.xml'
with open(outputfile, 'w') as f:
obj.export(f, 0, namespaceprefix_='')

diff = main.diff_files(inputfile, outputfile)
print(diff)
assert len(diff) == 0

def test_enviar_lote_rps_envio():
xml_path = 'nfse/ginfes/enviar_lote_rps_envio'
execute_test(xml_path, servico_enviar_lote_rps_envio)

def test_consultar_nfse_rps_envio():
xml_path = 'nfse/ginfes/consultar_nfse_rps_envio'
execute_test(xml_path, servico_consultar_nfse_rps_envio)