Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianoMafraJunior committed Mar 11, 2024
1 parent 576c3bf commit dd4807b
Show file tree
Hide file tree
Showing 4 changed files with 322 additions and 1 deletion.
Binary file added test/data/Logo-Engenere.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
212 changes: 212 additions & 0 deletions test/data/NFe_teste_2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
<infNFe versao="4.00" Id="NFe35200681583054000129550010000000012760018057">
<ide>
<cUF>35</cUF>
<cNF>76001805</cNF>
<natOp>Venda</natOp>
<mod>55</mod>
<serie>1</serie>
<nNF>1</nNF>
<dhEmi>2020-06-04T13:58:46+02:00</dhEmi>
<dhSaiEnt>2020-06-04T13:58:46+02:00</dhSaiEnt>
<tpNF>1</tpNF>
<idDest>1</idDest>
<cMunFG>3550308</cMunFG>
<tpImp>1</tpImp>
<tpEmis>1</tpEmis>
<cDV>7</cDV>
<tpAmb>2</tpAmb>
<finNFe>1</finNFe>
<indFinal>1</indFinal>
<indPres>0</indPres>
<procEmi>0</procEmi>
<verProc>Odoo Brasil OCA v14</verProc>
</ide>
<emit>
<CNPJ>81583054000129</CNPJ>
<xNome>Empresa Lucro Presumido Ltda</xNome>
<xFant>Empresa Lucro Presumido</xFant>
<enderEmit>
<xLgr>Avenida Paulista</xLgr>
<nro>3</nro>
<xBairro>Bela Vista</xBairro>
<cMun>3550308</cMun>
<xMun>São Paulo</xMun>
<UF>SP</UF>
<CEP>01311000</CEP>
<cPais>1058</cPais>
<xPais>Brasil</xPais>
<fone>551199999999</fone>
</enderEmit>
<IE>078016350838</IE>
<CRT>3</CRT>
</emit>
<dest>
<CNPJ>81493979000189</CNPJ>
<xNome>NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL</xNome>
<enderDest>
<xLgr>Rua Samuel Morse</xLgr>
<nro>135</nro>
<xCpl>20º andar - Conjunto 151</xCpl>
<xBairro>Brooklin</xBairro>
<cMun>3550308</cMun>
<xMun>São Paulo</xMun>
<UF>SP</UF>
<CEP>04576060</CEP>
<cPais>1058</cPais>
<xPais>Brasil</xPais>
<fone>551134782150</fone>
</enderDest>
<indIEDest>1</indIEDest>
<IE>460429771334</IE>
<email>[email protected]</email>
</dest>
<det nItem="1">
<prod>
<cProd>E-COM07</cProd>
<cEAN>SEM GTIN</cEAN>
<xProd>[E-COM07] Large Cabinet</xProd>
<NCM>94033000</NCM>
<CFOP>5102</CFOP>
<uCom>UN</uCom>
<qCom>1.0000</qCom>
<vUnCom>320.0000000000</vUnCom>
<vProd>320.00</vProd>
<cEANTrib>SEM GTIN</cEANTrib>
<uTrib>UN</uTrib>
<qTrib>1.0000</qTrib>
<vUnTrib>320.0000000000</vUnTrib>
<indTot>1</indTot>
</prod>
<imposto>
<vTotTrib>0.00</vTotTrib>
<ICMS>
<ICMS00>
<orig>5</orig>
<CST>00</CST>
<modBC>0</modBC>
<vBC>320.00</vBC>
<pICMS>12.0000</pICMS>
<vICMS>38.40</vICMS>
</ICMS00>
</ICMS>
<IPI>
<cEnq>999</cEnq>
<IPINT>
<CST>53</CST>
</IPINT>
</IPI>
<PIS>
<PISAliq>
<CST>01</CST>
<vBC>320.00</vBC>
<pPIS>0.6500</pPIS>
<vPIS>2.08</vPIS>
</PISAliq>
</PIS>
<COFINS>
<COFINSAliq>
<CST>01</CST>
<vBC>320.00</vBC>
<pCOFINS>3.0000</pCOFINS>
<vCOFINS>9.60</vCOFINS>
</COFINSAliq>
</COFINS>
</imposto>
</det>
<det nItem="2">
<prod>
<cProd>FURN_8855</cProd>
<cEAN>SEM GTIN</cEAN>
<xProd>[FURN_8855] Drawer</xProd>
<NCM>94033000</NCM>
<CFOP>5101</CFOP>
<uCom>UN</uCom>
<qCom>1.0000</qCom>
<vUnCom>3645.0000000000</vUnCom>
<vProd>3645.00</vProd>
<cEANTrib>SEM GTIN</cEANTrib>
<uTrib>UN</uTrib>
<qTrib>1.0000</qTrib>
<vUnTrib>3645.0000000000</vUnTrib>
<indTot>1</indTot>
</prod>
<imposto>
<vTotTrib>0.00</vTotTrib>
<ICMS>
<ICMS00>
<orig>5</orig>
<CST>00</CST>
<modBC>0</modBC>
<vBC>3827.25</vBC>
<pICMS>12.0000</pICMS>
<vICMS>459.27</vICMS>
</ICMS00>
</ICMS>
<IPI>
<cEnq>999</cEnq>
<IPITrib>
<CST>50</CST>
<vBC>3645.00</vBC>
<pIPI>5.0000</pIPI>
<vIPI>182.25</vIPI>
</IPITrib>
</IPI>
<PIS>
<PISAliq>
<CST>01</CST>
<vBC>3645.00</vBC>
<pPIS>0.6500</pPIS>
<vPIS>23.69</vPIS>
</PISAliq>
</PIS>
<COFINS>
<COFINSAliq>
<CST>01</CST>
<vBC>3645.00</vBC>
<pCOFINS>3.0000</pCOFINS>
<vCOFINS>109.35</vCOFINS>
</COFINSAliq>
</COFINS>
</imposto>
<infAdProd>Valor Aprox. dos Tributos: R$ 182.25</infAdProd>
</det>
<total>
<ICMSTot>
<vBC>4147.25</vBC>
<vICMS>497.67</vICMS>
<vICMSDeson>0.00</vICMSDeson>
<vFCP>0.00</vFCP>
<vBCST>0.00</vBCST>
<vST>0.00</vST>
<vFCPST>0.00</vFCPST>
<vFCPSTRet>0.00</vFCPSTRet>
<vProd>3965.00</vProd>
<vFrete>0.00</vFrete>
<vSeg>0.00</vSeg>
<vDesc>0.00</vDesc>
<vII>0.00</vII>
<vIPI>182.25</vIPI>
<vIPIDevol>0.00</vIPIDevol>
<vPIS>25.77</vPIS>
<vCOFINS>118.95</vCOFINS>
<vOutro>0.00</vOutro>
<vNF>4147.25</vNF>
</ICMSTot>
</total>
<transp>
<modFrete>9</modFrete>
</transp>
<pag>
<detPag>
<indPag>0</indPag>
<tPag>01</tPag>
<vPag>4147.25</vPag>
</detPag>
<vTroco>0.00</vTroco>
</pag>
<infAdic>
<infAdFisco>Documento emitido por: Marc Demo</infAdFisco>
</infAdic>
</infNFe>
</NFe>
111 changes: 110 additions & 1 deletion test/test_brazil_fiscal_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_format_number(self):
def test_create_danfe_pdf(self):
current_dir = os.path.dirname(os.path.realpath(__file__))

xml_file_path = os.path.join(current_dir, "data", "NFe_teste_cee.xml")
xml_file_path = os.path.join(current_dir, "data", "NFe_teste_1.xml")
with open(xml_file_path, "r", encoding="utf8") as f:
xmls = [f.read()]
pdf = pdf_docs.Danfe(
Expand All @@ -31,6 +31,115 @@ def test_create_danfe_pdf(self):

self.assertTrue(os.path.isfile("danfe.pdf"))

def test_create_danfe_pdf_logo(self):
current_dir = os.path.dirname(os.path.realpath(__file__))

xml_file_path = os.path.join(current_dir, "data", "NFe_teste_1.xml")
logo_file_path = os.path.join(current_dir, "data", "Logo-Engenere.jpg")
with open(xml_file_path, "r", encoding="utf8") as f:
xmls = [f.read()]
pdf = pdf_docs.Danfe(
xmls=xmls, image=logo_file_path, cfg_layout="ICMS_ST", receipt_pos="top"
)
pdf.output("danfe_logo.pdf")

self.assertTrue(os.path.isfile("danfe_logo.pdf"))

def test_create_danfe_pdf_paisagem(self):
current_dir = os.path.dirname(os.path.realpath(__file__))
xml_file_path = os.path.join(current_dir, "data", "NFe_teste_1.xml")

with open(xml_file_path, "r", encoding="utf8") as f:
xmls = [f.read()]
pdf = pdf_docs.Danfe(
xmls=xmls, image=None, cfg_layout="ICMS_ST", receipt_pos="top"
)

pdf.recibo_l()
pdf.output("danfe_paisagem.pdf")
self.assertTrue(os.path.isfile("danfe_paisagem.pdf"))

def test_create_danfe_emit_l(self):
current_dir = os.path.dirname(os.path.realpath(__file__))
xml_file_path = os.path.join(current_dir, "data", "NFe_teste_1.xml")

with open(xml_file_path, "r", encoding="utf8") as f:
xmls = [f.read()]
pdf = pdf_docs.Danfe(
xmls=xmls, image=None, cfg_layout="ICMS_ST", receipt_pos="top"
)

pdf.emit_l()

self.assertEqual(pdf.nr_pages, 1)
self.assertEqual(
pdf.recibo_text,
"RECEBEMOS DE Empresa Lucro Presumido Ltda OS PRODUTOS/SERVIÇOS CONSTANTES DA NOTA FISCAL INDICADA ABAIXO. "
"EMISSÃO: 01/01/2020 VALOR TOTAL: 1.950,00 DESTINATARIO: NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - "
"SEM VALOR FISCAL - Rua do Bosque, 238, Barra Funda, São Paulo - SP",
)
self.assertEqual(pdf.font_family, "times")
self.assertEqual(pdf.font_size, 14.111111111111109)

def test_create_danfe_dest_l(self):
current_dir = os.path.dirname(os.path.realpath(__file__))
xml_file_path = os.path.join(current_dir, "data", "NFe_teste_1.xml")

with open(xml_file_path, "r", encoding="utf8") as f:
xmls = [f.read()]
pdf = pdf_docs.Danfe(
xmls=xmls, image=None, cfg_layout="ICMS_ST", receipt_pos="top"
)

pdf.dest_l()

self.assertEqual(pdf.nr_nota, "2")
self.assertEqual(pdf.nr_pages, 1)
self.assertEqual(pdf.page, 1)
self.assertEqual(pdf.title, "DANFE")
self.assertEqual(pdf.font_size, 2.822222222222222)
self.assertEqual(pdf.b_margin, 10.0)

def test_create_danfe_fat_l(self):
current_dir = os.path.dirname(os.path.realpath(__file__))
xml_file_path = os.path.join(current_dir, "data", "NFe_teste_2.xml")

with open(xml_file_path, "r", encoding="utf8") as f:
xmls = [f.read()]
pdf = pdf_docs.Danfe(
xmls=xmls, image=None, cfg_layout="ICMS_ST", receipt_pos="top"
)

pdf.fat_l()

self.assertEqual(pdf.nr_nota, "1")
self.assertEqual(pdf.nr_pages, 1)
self.assertEqual(pdf.page, 1)
self.assertEqual(pdf.title, "DANFE")
self.assertEqual(pdf.font_size, 2.469444444444444)
self.assertEqual(pdf.b_margin, 10.0)

def test_create_danfe_transp_l(self):
current_dir = os.path.dirname(os.path.realpath(__file__))
xml_file_path = os.path.join(current_dir, "data", "NFe_teste_2.xml")

with open(xml_file_path, "r", encoding="utf8") as f:
xmls = [f.read()]
pdf = pdf_docs.Danfe(
xmls=xmls, image=None, cfg_layout="ICMS_ST", receipt_pos="top"
)

pdf.transp_l()

self.assertEqual(pdf.nr_nota, "1")
self.assertEqual(pdf.nr_pages, 1)
self.assertEqual(pdf.page, 1)
self.assertEqual(pdf.title, "DANFE")
self.assertEqual(pdf.font_size, 2.822222222222222)
self.assertEqual(pdf.b_margin, 10.0)
self.assertEqual(pdf.l_margin, 9.999999999999998)
self.assertEqual(pdf.font_family, "times")


if __name__ == "__main__":
unittest.main()

0 comments on commit dd4807b

Please sign in to comment.