15 changed files with 167 additions and 193 deletions
-
2.travis.yml
-
25pytrustnfe/nfe/__init__.py
-
12pytrustnfe/nfe/assinatura.py
-
4pytrustnfe/nfse/paulistana/__init__.py
-
77pytrustnfe/test/test_assinatura.py
-
63pytrustnfe/test/test_certificado.py
-
49pytrustnfe/test/test_comunicacao.py
-
22pytrustnfe/test/test_consulta_cadastro.py
-
18pytrustnfe/test/test_danfe.py
-
7pytrustnfe/test/test_envio_nfe.py
-
21pytrustnfe/test/test_utils.py
-
6pytrustnfe/test/test_xml_serializacao.py
-
30pytrustnfe/test/xml_assinado.xml
-
22pytrustnfe/xml/__init__.py
-
2requirements.txt
@ -1,51 +1,56 @@ |
|||
#coding=utf-8 |
|||
# coding=utf-8 |
|||
''' |
|||
Created on Jun 14, 2015 |
|||
|
|||
@author: danimar |
|||
''' |
|||
from lxml import etree |
|||
import unittest |
|||
import os, os.path |
|||
from pytrustnfe.servicos.Assinatura import Assinatura |
|||
import os |
|||
import os.path |
|||
from pytrustnfe.nfe.assinatura import Assinatura |
|||
|
|||
|
|||
XML_ASSINAR = '<?xml version="1.0" encoding="UTF-8"?>' \ |
|||
'<!DOCTYPE Envelope [ ' \ |
|||
' <!ATTLIST Data Id ID #IMPLIED>' \ |
|||
']>' \ |
|||
'<Envelope xmlns="urn:envelope">' \ |
|||
' <Data Id="NFe43150602261542000143550010000000761792265342">' \ |
|||
' Hello, World!' \ |
|||
' </Data>' \ |
|||
'</Envelope>' |
|||
'<Envelope xmlns="urn:envelope">' \ |
|||
' <Data Id="NFe43150602261542000143550010000000761792265342">'\ |
|||
' Hello, World!' \ |
|||
' </Data>' \ |
|||
'</Envelope>' |
|||
|
|||
XML_ERRADO = '<?xml version="1.0" encoding="UTF-8"?>' \ |
|||
'<Envelope xmlns="urn:envelope">' \ |
|||
' <Data Id="NFe43150602261542000143550010000000761792265342">' \ |
|||
' Hello, World!' \ |
|||
' </Data>' \ |
|||
'</Envelope>' |
|||
|
|||
class test_assinatura(unittest.TestCase): |
|||
|
|||
caminho = os.path.dirname(__file__) |
|||
XML_ERRADO = '<?xml version="1.0" encoding="UTF-8"?>' \ |
|||
'<Envelope xmlns="urn:envelope">' \ |
|||
' <Data Id="NFe">' \ |
|||
' Hello, World!' \ |
|||
' </Data>' \ |
|||
'</Envelope>' |
|||
|
|||
def test_assinar_xml_arquivo_invalido(self): |
|||
assinatura = Assinatura(os.path.join(self.caminho, 'teste_nao_existe.pfx'), '123456') |
|||
self.assertRaises(Exception, assinatura.assina_xml, XML_ASSINAR) |
|||
|
|||
def test_assinar_xml_senha_invalida(self): |
|||
assinatura = Assinatura(os.path.join(self.caminho,'teste.pfx'), '123') |
|||
self.assertRaises(Exception, assinatura.assina_xml, XML_ASSINAR) |
|||
class test_assinatura(unittest.TestCase): |
|||
|
|||
def test_assinar_xml_invalido(self): |
|||
assinatura = Assinatura(os.path.join(self.caminho,'teste.pfx'), '123456') |
|||
self.assertRaises(RuntimeError, assinatura.assina_xml, XML_ERRADO) |
|||
caminho = os.path.dirname(__file__) |
|||
|
|||
def test_assinar_xml_valido(self): |
|||
assinatura = Assinatura(os.path.join(self.caminho,'teste.pfx'), '123456') |
|||
xml = assinatura.assina_xml(XML_ASSINAR) |
|||
xml_assinado = open(os.path.join(self.caminho, 'xml_assinado.xml'), 'r').read() |
|||
|
|||
def test_assinar_xml_senha_invalida(self): |
|||
pfx = open(os.path.join(self.caminho, 'teste.pfx')).read() |
|||
signer = Assinatura(pfx, '123') |
|||
self.assertRaises(Exception, signer.assina_xml, signer, |
|||
etree.fromstring(XML_ASSINAR), |
|||
'NFe43150602261542000143550010000000761792265342') |
|||
|
|||
def test_assinar_xml_invalido(self): |
|||
pfx = open(os.path.join(self.caminho, 'teste.pfx')).read() |
|||
signer = Assinatura(pfx, '123456') |
|||
self.assertRaises(Exception, signer.assina_xml, signer, |
|||
etree.fromstring(XML_ERRADO), |
|||
'NFe43150602261542000143550010000000761792265342') |
|||
|
|||
def test_assinar_xml_valido(self): |
|||
pfx = open(os.path.join(self.caminho, 'teste.pfx')).read() |
|||
signer = Assinatura(pfx, '123456') |
|||
xml = signer.assina_xml( |
|||
etree.fromstring(XML_ASSINAR), |
|||
'NFe43150602261542000143550010000000761792265342') |
|||
xml_assinado = open(os.path.join(self.caminho, 'xml_assinado.xml'), |
|||
'r').read() |
|||
self.assertEqual(xml_assinado, xml, 'Xml assinado é inválido') |
|||
|
|||
|
|||
@ -1,33 +1,27 @@ |
|||
#coding=utf-8 |
|||
# coding=utf-8 |
|||
''' |
|||
Created on 22/06/2015 |
|||
|
|||
@author: danimar |
|||
''' |
|||
import unittest |
|||
from pytrustnfe.servicos.NfeConsultaCadastro import NfeConsultaCadastro |
|||
from pytrustnfe.xml.DynamicXml import DynamicXml |
|||
from unittest import skip |
|||
from pytrustnfe.nfe import consulta_cadastro |
|||
|
|||
|
|||
class Test(unittest.TestCase): |
|||
|
|||
def setUp(self): |
|||
unittest.TestCase.setUp(self) |
|||
c = DynamicXml('ConsCad') |
|||
c(xmlns="http://www.portalfiscal.inf.br/nfe", versao="2.00") |
|||
c.infCons.xServ = 'CONS-CAD' |
|||
c.infCons.UF = 'SC' |
|||
c.infCons.CNPJ = '82951310000156' |
|||
self.objeto_consulta = c |
|||
|
|||
@skip('Pulando') |
|||
def test_consulta_cadastro(self): |
|||
try: |
|||
dir_pfx = '/home/danimar/projetos/isotelha.pfx' #Hack |
|||
|
|||
com = NfeConsultaCadastro(dir_pfx, 'iso@#telha') |
|||
dir_pfx = 'teste.pfx' |
|||
com = consulta_cadastro(dir_pfx, 'iso@#telha') |
|||
xml, objeto = com.consultar_cadastro(self.objeto_consulta, 'SC') |
|||
|
|||
|
|||
print xml |
|||
print objeto |
|||
except Exception as e: |
|||
print(str(e)) |
|||
print(str(e)) |
|||
@ -1,18 +0,0 @@ |
|||
''' |
|||
Created on 01/07/2015 |
|||
|
|||
@author: danimar |
|||
''' |
|||
import unittest |
|||
from pytrustnfe.pdf.Danfe import Danfe |
|||
from pytrustnfe.xml.DynamicXml import DynamicXml |
|||
|
|||
class test_danfe(unittest.TestCase): |
|||
|
|||
def test_geracao_danfe(self): |
|||
nfe = DynamicXml('ProtNFe') |
|||
pdf = Danfe(nfe) |
|||
pdf.gerar() |
|||
|
|||
|
|||
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue